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.
- The first block of code registers the mapping for our custom controllers.
- 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.
- 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
- The patch include file to extend the httpRequestBegin processor to register our custom mapping.