A generic content api for Umbraco CMS.
Serializes the content in Umbraco to Json. It's possible to adapt how a specific Umbraco property gets serialized by adding custom "Property converter". The nuget package include a set of standard property converters.
Latest known version of Umbraco that this nuget have been successfully tested with: v7.7.7
PM> Install-Package EOls.UmbracoContentApi
[GET] /umbraco/api/content/get/{id}
If you want to adapt how a specific Umbraco property is serialized. Just add a class that implements the interface IApiPropertyConverter, and decorate the class with the PropertyTypeAttribute.
All property converters (and document extenders) will be located by using reflection during site startup.
In this example the text "Awesome!" will be added to the content when an Umbraco property of type "Umbraco.TinyMCEv3" is serialized.
[PropertyType(Type = "Umbraco.TinyMCEv3")]
public class RichTextEditorConverter : IApiPropertyConverter
{
public object Convert(IPublishedProperty property, IPublishedContent owner, ContentSerializer serializer, UmbracoHelper umbraco)
{
var htmlString = property.Value as HtmlString;
return htmlString != null ? htmlString.ToHtmlString() + "Awesome!" : string.Empty;
}
}
It's possible to extend a document type by creating a class with the IDocumentTypeExtender interface. When the api returns content with this document type, it will include the additional data.
Let's say you have a document type named "Home". For this specific document type you also want to return some additional data.
public class HomeDocument : IDocumentTypeExtender
{
public Dictionary<string, object> Extend(IPublishedContent content, ContentSerializer serializer, UmbracoHelper umbra)
{
return new Dictionary<string, object>() { { "Foo", "Bar" } };
}
}
It's possible to "hide" a specific property, or the entire document type, from being returned by the API.
Hide document type named "Settings"
[DocumentTypeSettingsAttribute(Hide = true)]
public class SettingsDocument { }
Hide properties "myNonPublicProperty" and "myOtherProperty" on document type "Settings"
[DocumentTypeSettingsAttribute(HideProperties = new[]{"myNonPublicProperty","myOtherProperty"}))]
public class SettingsDocument { }