Smart Systems
connecting Businesses

Article

SDL Tridion Core Service content exposed via a REST web service

I recently had to implement a REST web service that exposes SDL Tridion Core Service content.  I was surprised by how easy it was and thought that I’d highlight the relevant parts to encourage others to try it.

My REST web service is part of an MVC website that has its own collection of controllers.  So I’ve elected to put my REST controllers into a sub-folder called CMS.

MVC controller location

In Visual Studio a default MVC application also has an App_Start folder with a WebApiConfig.cs file inside it.

App-start-web-api-config.jpg

The Global.asax.cs file hooks it up to the Application_Start event.

Global-asax-application-start.jpg

By default this code adds a ‘Route’ of “api/{controller}/{id}”.  However I’ve modified ours to be “CMS” instead of “api”.

Web-api-config-register.jpg

That’s all the infrastructure in place, now we just need to populate the controller (added in screen shot #1 above).

Take a deep breath and prepare yourself folks, it’s about to get super complex……

rest-controller.jpg

So I’ve only hooked up lines 13 and 19 for now.  But what that code means is we can do this:

rest response publication list

And this:

rest response publication item

A REST web service exposing Tridion content via Core Service.  Don’t forget to secure the thing!

This article was originally published by Mark Sizer at: http://www.tridiondeveloper.com/sdl-tridion-core-service-content-exposed-via-a-rest-web-service