Skip to content
A package that enables easy integration of Headless Api functionality into your project.
JavaScript HTML C# Other
Branch: master
Clone or download
Latest commit 777257f Sep 26, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/UmbracoContentApi Updated login info Sep 26, 2019
.gitignore Updated login info Sep 26, 2019
GitVersion.yml
License.txt Added license Sep 13, 2019
README.md Updated readme with nuget link Sep 19, 2019
azure-pipelines.yml Update azure-pipelines.yml for Azure Pipelines Sep 24, 2019

README.md

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+

You can’t perform that action at this time.