Friday, January 20, 2012

Building a REST service in MVC .NET

This article got me started on the right track to implement a REST service in MVC:
http://iwantmymvc.com/rest-service-mvc3


One thing i think could be done more straightforward than in the examples is the switching on Http method. Instead of creating a filter to add a parameter to the method call i use the HttpMethod property of the Request object wich is available in you controller.

Code Snippet
  1. [Authorize]
  2. [AcceptVerbs(HttpVerbs.Delete|HttpVerbs.Get)]
  3. public ActionResult activities(Guid id) {
  4.     switch (Request.HttpMethod)
  5.     {
  6.         case "GET":
  7.             return Json(new ActivityViewModel());
  8.         case "DELETE":
  9.             return Json(true);
  10.     }
  11.     return Json(new { Error = true, Message = "Unsupported HTTP verb" });
  12. }

Thursday, January 19, 2012

A fresh start

I'm starting this blog for myself to have a history of references i use in my daily life.
It might prove usefull for others or not, let's see.