Use as a headless CMS

Besides working as a traditional content management system, Kaliko CMS can also act as a headless CMS. This is achieved through the optional KalikoCMS.Headless-package which includes a content API.

A headless or decoupled CMS is a way to separate content management from presentation, allowing the content to be consumed by something like a mobile app or a single page application.

Kaliko CMS is offering this feature as an optional NuGet-package called KalikoCMS.Headless. When you install this package you'll get a content API which you can access in order to retrieve your content. You declare your page types as usual by code as well as building your content in the normal administration interface. The main difference is the way you access your content.

The headless feature is an add-on and works side-by-side with both the normal MVC or WebForms providers. This means that you can use the CMS both traditionally and headless at the same time, for instance using parts of the structure to feed a mobile app.

In order for the CMS to start correctly either the MVC or WebForms provider needs to be installed, but you don't need to implement server side rendering if you don't want to (see the headless demo project for an example).

Installing the content API

Add the NuGet-package KalikoCMS.Headless to your web project where you already have a Kaliko CMS installation (see Installation if you need help with setting the system up).

If your project doesn't already have WebApi configured, you need to add the following configuration:

App_Start\WebApiConfig.cs

namespace YourNamespaceHere {
using System.Web.Http;
using System.Web.Http.Cors; public class WebApiConfig {
public static void Register(HttpConfiguration config) {
// If you will request content data from another domain, you need to register it here:
var cors = new EnableCorsAttribute("http://localhost:3000", "*", "*");
config.EnableCors(cors);
// KalikoCMS Content API needs attribute routes to be configured:
config.MapHttpAttributeRoutes();
}
}
}

And regestering the configuration by adding the highlighted line below:

Global.asax.cs

namespace YourNamespaceHere {
  using System;
  using System.Web.Http;

  public class Global : System.Web.HttpApplication {
    protected void Application_Start(object sender, EventArgs e) {
// ...
      GlobalConfiguration.Configure(WebApiConfig.Register);
// ...
    }
  }
}

Demo project based on React

A demo project has been created as an example on how to work with the headless feature. The project includes both a sample installation of Kaliko CMS with data as well as a small React application that consumes content through the content API. The main purpose is to show how to fetch content from a decoupled application.

You'll find the headless demo project at GitHub

Content API

Only currently published pages are return through the content API, which means that work-in-progress or deleted pages are pre-filtered in the response.

Page types

The following API calls can be made in order to fetch information about page types or batch read all pages of a particular type. {id} refers to PageTypeId. All calls in this section are called as GET actions.

Path Description
/contentapi/v1.0/pagetype/all Get a list of all available page types
/contentapi/v1.0/pagetype/{id} Get information about one specific page type based on ID
/contentapi/v1.0/pagetype/{id}/pages Get all pages from the CMS of one specific page type based on ID

Pages

The following API calls can be made in order to fetch single or multiple pages from the CMS. {id} refers to PageId. All calls except /contentapi/v1.0/page/resolve are called as GET actions.

Path Description
/contentapi/v1.0/page/startpage Get the start page
/contentapi/v1.0/page/all Get all pages from the CMS
/contentapi/v1.0/page/{id} Get a page based on ID
/contentapi/v1.0/page/{id}/children Get all children for a page based on ID
/contentapi/v1.0/page/{id}/descendents Get all descendents of a page based on ID
/contentapi/v1.0/page/{id}/parent Get the parent of a page based on ID
/contentapi/v1.0/page/{id}/ancestors Get all ancestors of a page based on ID
/contentapi/v1.0/page/resolve

Returns a page based on the relative URL passed in the request. This is done through a POST request where the relative URL is sent in the body.

Example of such a call:

POST http://domain/contentapi/v1.0/page/resolveurl/ HTTP/1.1
Content-Type: application/json
cache-control: no-cache
Accept: */*
Host: localhost:59558
accept-encoding: gzip, deflate
content-length: 28
Connection: keep-alive

"/news/everything-is-great/"

Site

The following API call can be used to fetch information about the site.

Path Description
/contentapi/v1.0/site Get the site and its properties

Making test calls to the API

For making test calls to the API a tool such as Postman is recommended. Please note that the API has been created with JSON in mind, so make sure to set Accept to application/json in the request header.