Headless Sitecore

Created: 13 Jun 2017, last update: 24 Jun 2017

Headless Sitecore the possibilities

For some applications, you just want to get the content RESTful, JSON from Sitecore, prefer personalized and with multivar testing capability. Think about mobile apps and internet or things, IoT or just a tool on a web page.

What options do you have as Sitecore developer with regard to headless and what's in Sitecore's roadmap for iOT, Mobile and Headless?

Lars Fløe Nielsen, Sitecore CDO says:

Let me explain. Sitecore stores content as small objects, and our layout engine places those objects, or modules, in a web presentation format. Similarly, a mobile app developer can use our API to call those content objects and reuse them in a mobile app. So when a marketer changes your brand’s web content in Sitecore, those changes automatically propagate across any channel on which you’ve called or reused those content objects. With our Experience Editor, you can edit and preview content components (or modules) on a page. You can do the same in AEM and other products. Many CMSes make it appear as though you’re editing content components on the page, but the similarity ends there. See Sitecore as a true headless CMS.

See Sitecore as a true headless CMS

So we can use the Sitecore API,
There is The ItemService and the The RESTful API for the ItemService. Or before Sitecore 7.5 we can use the “Item Web API” So out of the box you can use this but no personalization and such it support various queries too look around in your Sitecore very flexible. However this is not always what you want think about security or more complex queries just in one call. Exactly what you need no more or less then the itemService does not meet properly.

The Future
The following sheet from SUGCON 2017 keynote show that a Content API with personalization is planned.

OData Content API with PersonalizationOData Content API with Personalization

Also Sitecore is working on xConnect Client, a API to get data in and out Sitecore xDB.

Also Sitecore is working on Sitecore JavaScript Services (JSS), an approach that allow JavaScript for example ReactJS to get the content from Sitecore. And also work in Experience editor with personalization and multivar testing. Presented on SUGCON 2017.

From the track description of Sitecore symposium 2017 “New features available in Sitecore 9 that facilitate running Sitecore in a headless mode."

Another approach, SXA
Today Sitecore Experience Accelerator, SXA default support JSON output, also in the Experience editor with personalization and multivar testing.

Custom API
By just using the Device function in Sitecore you can very quick creat something similar to the SXA approach. And also easy to add some additional advance option, beside personalization and multivar testing adding Identify, tells Sitecore which contact do te call. And adding values to xDB. If you use the device option and use renderings/sublayouts on the layout to create the JSON than you can use personalization and multivar testing out of the box. Other option just create your JSON without use of the Sitecore Layout, very flexible in what and how the JSON looks like but no OOTB personalization and multivar testing. But Identify of adding valus to xDB is Is still easy to realize.

Example code for identify

if (Tracker.Current != null) {
  if (Sitecore.Analytics.Tracker.Current.Contact.Identifiers.Identifier != uniqueUsername)