While having Hands on for the ASP.NET Web API2 Attribute Routing feature, I observe some strange differences for this feature.
To use attribute route we have to use the Route("") attribute and specify the custom routes.
[Route("api/books")] public IEnumerable<Book> GetBooks() { ... } [Route("api/books/{id:int}")] public Book GetBook(int id) { ... }Also there is change in
HttpPost,HttpGet,HttpPutandHttpDeleteattributes in WebAPI 2. It introduces additional constructor to specify the Routing using the Attribute. (Example - Simple Talk by Dino and Visual Studio Magazine article)[HttpGet("orders/{id:int:range(1, 100)}/show"]
I installed the Microsoft ASP.NET and Web Tools 2013.1 for Visual Studio 2012 and using the the Web API2 Empty Project Template created the Sample WebAPI2 application. There If we use the HttpPost Attribute with route as string it gives error, Constructor cannot take attribute.
I also tried the same thing using nuget Package Microsoft.AspNet.WebApi version 5.0.0. Then I downloaded the source code of Article listed in Visual Studio Magazine Article. But strange thing is there I can see the use of HttpPost attribute which takes input route. There is one difference i noticed that System.Web.Http.HttpPostAttribute is derived from HttpVerbAttribute, where as in my version of System.Web.Http.HttpPostAttribute is derived from Attribute and implements IActionHttpMethodProvider Interface
I went on and downloaded the Asp.NET Mvc source code from CodePlex, but strange I did not find the System.Web.Http.HttpPostAttribute implementation with default constructor and single parameter constructor.
Am I missing anything here.