Skip to content

skttl/UmbracoContentApi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nuget (with prereleases)

Umbraco Content Api

The Umbraco Content Api is a package that enables easy integration of Headless Api functionality into your project. The package includes converters for all default Umbraco porperty editors and allows developers to add to and replace them at will.

Out of the box easy to use, full DI support and fast.

Basic Usage:

  1. Download the package from NuGet
  2. Install the package
  3. Create an UmbracoApiController
  4. Inject the content resolver
  5. Resolve the content
public class SampleApiController : UmbracoApiController
    {
        private readonly Lazy<IContentResolver> _contentResolver;

        public ContentApiController(Lazy<IContentResolver> contentResolver)
        {
            _contentResolver = contentResolver;
        }

        public IHttpActionResult Get(Guid id)
        { 
            IPublishedContent content = Umbraco.Content(id);
            var model = _contentResolver.Value.ResolveContent(content);
            return Ok(model);
        }
    }

Creating and adding a converter

To create a converter for your custom editor you need to implement the IConverter interface.

// Converter:
public class SampleConverter : IConverter
    {
        public string EditorAlias => "My.PropertyEditorAlias";

        public object Convert(object value)
        {
            // If the value is already in a json supported format, just return it.
            // Otherwise convert it to a friendly format here.
            return value;
        }
    }
// Composer:
    [ComposeAfter(typeof(UmbracoContentApi.Core.Composers.ConvertersComposer))]
    public class ConverterComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.Converters().Append<SampleConverter>();
        }
    }

Replace an exsisting converter

To replace a converter just add the following to the composer:

composition.Converters()
    .Replace<ConverterToReplace, SampleConverter>();

Compatibility

The Umbraco Content Api works with Umbraco 8.1.3+

Sample app login

email: admin@contentapi.com password: Password123!

Changelog

2.0.0

Added options params to all converters.

About

A package that enables easy integration of Headless Api functionality into your project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 83.0%
  • HTML 14.8%
  • C# 1.6%
  • Other 0.6%