1

If I design my controller in such a way:

public class ItemController : ApiController
{
    [HttpGet]
    [RoutePrefix("item/dosomething")]
    public void DoSomething(Item item)
    { }

    [HttpGet]
    [RoutePrefix("item/dosomethingnicer")]
    public void DoSomethingNicer(Item item)
    { }

    [HttpGet]
    [RoutePrefix("item/dosomethingelse")]
    public void DoSomethingElse(Item item)
    { }
}

Would this work?

1
  • 2
    Define "work". Also, RoutePrefix should be used on classes not methods for that you can use Route instead. Commented May 25, 2016 at 11:43

2 Answers 2

2

I would expect a structure more akin to this:

[RoutePrefix("item")]
public class ItemController : ApiController
{
    [HttpGet]
    [Route("dosomething")]
    public void DoSomething(Item item)
    { }

    [HttpGet]
    [Route("dosomethingnicer")]
    public void DoSomethingNicer(Item item)
    { }

    [HttpGet]
    [Route("dosomethingelse")]
    public void DoSomethingElse(Item item)
    { }
}
Sign up to request clarification or add additional context in comments.

Comments

0

I use Web Api 2 in this way in a lot of Controllers:

[HttpGet]
[Route("~/api/{version}/research/export")]
public IHttpActionResult Export(){
     do stuff...
} 

[HttpPost]
[Route("~/api/{version}/research/list")]
public IHttpActionResult List()
{
     do stuff...
}

I use full api path description and it works with no problems.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.