API
Version 7.x > API > Using Web Api with Kentico. View modes: 
User avatar
Member
Member
magnus-tenk - 1/28/2013 2:29:21 PM
   
Using Web Api with Kentico.
I would really like to be able to use a Web Api controller with the system but I can't find a way to configure the route to my controller. Can you help me out here?

/Magnus

This is the actual route I would like to get in.
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "hammarsapi/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 1/29/2013 3:01:58 AM
   
RE:Using Web Api with Kentico.
Hi Magnus,

could you please tell me when/where are you setting the route?

Best regards,
Martin Danko

User avatar
Member
Member
magnus-tenk - 2/4/2013 5:44:26 PM
   
RE:Using Web Api with Kentico.
Hi. My response got delayed a bit, for some reason i had a problem posting in the forum a couple of days ago.

**************

I have only implemented it in another non Kentico-projekt but before going home yesterday I made a hack that works in Kentico, it's not pretty though. This is how, for an example ApiController. lets call it SearchController with the earlier mentioned routing configuration

1: Add the Route in CMSHttoApplication Application_start

2: make a folder structure in CmsDesk that end with an empty folder (no document) ~/hammarsapi/search

It works great now to access it with fiddler. Now I just have to figure out how to make the webpart to load the scripts and fire the getJSON.

/Magnus

User avatar
Member
Member
magnus-tenk - 2/14/2013 11:17:22 AM
   
RE:Using Web Api with Kentico.
Time for an update.

This technique works perfectly aside from using routeparameters. That does not work for quite obvious reasons (i cant create an empty folder structure for every possible optional path-parameter), so a Kentico backed solutions for integrating Web Api would be great. It would probably be closely related to your MVC-solution as it is the same routing engine.

The workaround I settled on is to use the trusted old query parameters. Not as elegant but, at least it allow me to use the goodness of Web Api, Jquery/Knockout and Kentico API in almost perfect harmony.

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 2/16/2013 9:03:33 AM
   
RE:Using Web Api with Kentico.
Hi Magnus,

Thank you very much for the posts, really interesting workaround!

Best regards,
Martin Danko

User avatar
Certified Developer 13
Certified Developer 13
Accepted solutionAccepted solution
dgrant-ecentricarts - 2/14/2013 11:41:29 AM
   
RE:Using Web Api with Kentico.
Add your route (/hammarsapi) to excluded urls in Site Manager.

User avatar
Member
Member
magnus-tenk - 2/17/2013 5:40:33 PM
   
RE:Using Web Api with Kentico.
Brilliant! You should get a medal from Kentico for that tip :-)

/Magnus