Web API controller with async/await in Sitecore 8
So you want to create Web API controllers in a Sitecore 8 solution? Use Sitecore.Services.Infrastructure.Web.Http.ServicesApiController
and add Sitecore.Services.Core.ServicesControllerAttribute
to namespace your controller. Read Developer’s Guide to Sitecore.Services.Client (PDF) from page 61 and onward. Controllers will be reachable at:
/sitecore/api/ssc/{namespace}/{controller}/{id}/{action}
That’s it. No routing setup, no pipeline fiddling. Quick and easy! Just note that Sitecore does not support dependency injection in the controller - at least out of the box.
Below is a full example that shows async/await in a Web API controller - note the aspnet:UseTaskFriendlySynchronizationContext
appSetting in Web.config.
You might also want to check my post on disabling of Sitecore Web API filters.