WebAPI 2 native support in Sitecore 8.2

webapi-pic-300x300-2-2

Here we go with an other episode of the WebAPI and Sitecore saga…

As you probably know each version of Sitecore has managed WebAPI in a different way….

https://sitecorecommerce.wordpress.com/2014/11/30/webapi-attribute-routing-is-not-working-with-sitecore-7-5/

http://kamsar.net/index.php/2014/05/using-web-api-2-attribute-routing-with-sitecore/

Within 8.2 finally Sitecore is officially supporting WebApi NATIVELY

So what do you need to do to write your first WebAPI Controller and start using it?

very simple:

public class MyCustomController : Controller
{
   public ActionResult Test()
   {
      return Content("This is a test");
    }
}

and this is the Url where you can access your controller

Url: http://yourInstanceName/api/sitecore/MyCustom/test

public class MyOtherCustomController : Controller
{
   public ActionResult OtherTest(string mycustomId)
   {
      return Content("This is a test with params" + mycustomId);
    }
}

Url: http://yourInstanceName/api/sitecore/MyOtherCustom/OtherTest/thisIsMyParam

will return “This is a test with params thisIsMyParam”

Happy Sitecore and happy webApi to everybody!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s