Mike Robbins

Sitecore Developer Blog

Follow me on GitHub

Add Custom Web API Controller to Sitecore Solution

The below code snippet enables you to add a custom Web API controller to your sitecore solution.

  1. The first block of code registers the mapping for our custom controllers.
  2. Next we abort the sitecore httprequest pipeline for our custom controllers. Notice we ignore the "api/Sitecore" path, this is so we don't affect any of the existing sitecore controllers such as SPEAK, Entity Service and ItemService.
  3. Here I have created  a formatter for the Sitecore ID, this allows us to clean up the JSON formatting. I've described this method in the following blog post http://mikerobbins.co.uk/2014/12/02/web-api-sitecore-id-formatter/. This is then registered in RegisterWebApiRoute class
  4. The patch include file to extend the httpRequestBegin processor to register our custom mapping.