title: MVC3 REST Routes & Http Verbs
body: <p>As a result of a <a href="https://stackoverflow.com/questions/8610451/mvc3-restful-api-routing-http-verb-handling">previous question</a> of mine, I have discovered two ways of handling REST routes in MVC3.</p>
  
  <p>This is a followup question where I am trying to learn factual differences/subtleties between these two approaches. I am looking authoritative answer if possible.</p>
  
  <p><strong>Method 1: Single Route, with Action Name + Http Verb Attributes on Controller Actions</strong></p>
  
  <ol>
  <li><p>Register a single route in <code>Global.asax</code> using a specified <code>action</code> parameter.</p>
  
  <pre><code>public override void RegisterArea(AreaRegistrationContext context)
  {
      // actions should handle: GET, POST, PUT, DELETE
      context.MapRoute("Api-SinglePost", "api/posts/{id}", 
          new { controller = "Posts", action = "SinglePost" });
  }
  </code></pre></li>
  <li><p>Apply both <code>ActionName</code> and <code>HttpVerb</code> attributes to controller actions</p>
  
  <pre><code>[HttpGet]
  [ActionName("SinglePost")]
  public JsonResult Get(string id)
  {
      return Json(_service.Get(id));
  }
  [HttpDelete]
  [ActionName("SinglePost")]
  public JsonResult Delete(string id)
  {
      return Json(_service.Delete(id));
  }
  [HttpPost]
  [ActionName("SinglePost")]
  public JsonResult Create(Post post)
  {
      return Json(_service.Save(post));
  }
  [HttpPut]
  [ActionName("SinglePost")]
  public JsonResult Update(Post post)
  {
      return Json(_service.Update(post););
  }
  </code></pre></li>
  </ol>
  
  <p><strong>Method 2: Unique Routes + Verb Constraints, with Http Verb Attribute on Controller Actions</strong></p>
  
  <ol>
  <li><p>Register unique routes in <code>Global.asax</code> with <code>HttpMethodContraint</code></p>
  
  <pre><code>var postsUrl = "api/posts";
  
  routes.MapRoute("posts-get", postsUrl + "/{id}", 
      new { controller = "Posts", action = "Get",
      new { httpMethod = new HttpMethodConstraint("GET") });
  
  routes.MapRoute("posts-create", postsUrl, 
      new { controller = "Posts", action = "Create",
      new { httpMethod = new HttpMethodConstraint("POST") });
  
  routes.MapRoute("posts-update", postsUrl, 
      new { controller = "Posts", action = "Update",
      new { httpMethod = new HttpMethodConstraint("PUT") });
  
  routes.MapRoute("posts-delete", postsUrl + "/{id}", 
      new { controller = "Posts", action = "Delete",
      new { httpMethod = new HttpMethodConstraint("DELETE") });
  </code></pre></li>
  <li><p>Use only an Http Verb Attribute on the Controller Actions</p>
  
  <pre><code>[HttpGet]
  public JsonResult Get(string id)
  {
      return Json(_service.Get(id));
  }
  [HttpDelete]
  public JsonResult Delete(string id)
  {
      return Json(_service.Delete(id));
  }
  [HttpPost]
  public JsonResult Create(Post post)
  {
      return Json(_service.Save(post));
  }
  [HttpPut]
  public JsonResult Update(Post post)
  {
      return Json(_service.Update(post););
  }
  </code></pre></li>
  </ol>
  
  <p>Both of these methods let me have uniquely named Controller Action Methods, and allow for RESTful routes tied to the verbs... <em>but what is inherently different about restricting the route vs. using a proxy action name?</em></p>