1

Closed

Have RouteAttribute for attribute routing

description

Reading/writing the following code is a bit non-intuitive:
public class HomeController : ApiController
{
    [HttpGet("")]
    public string Get()
    {
        return "Hello, World!";
    }
}

  1. Why do I need to say Get again in the routing attribute? I already did in my method name.
  2. It doesn't look like a routing attribute. I'd prefer it to be called Route, to make it explicit I'm setting a route.
  3. It would be nice to be able to specify the full path, including the /.
So my preferred syntax would be:
public class HomeController : ApiController
{
    [Route("/")]
    public string Get()
    {
        return "Hello, World!";
    }
}
(That's what I initially tried to type when using this feature for the first time.)

Also, using [HttpGet] isn't great, as I believe it disables support for HEAD requests. In general, I think [Route], would be a better approach.
Closed Aug 13, 2013 at 12:57 AM by yishaigalatzer
Duplicate of https://aspnetwebstack.codeplex.com/workitem/1204, that has more details and has a bit more work in it.

comments

eilonlipton wrote Jun 14, 2013 at 7:31 AM

Please talk to Youssef about this to ensure that the design is consistent between MVC and Web API.