While it might not be possible to set multiple routes as in ASP.NET MVC, try to go for Attribute Routing to make use of easy to use annotations for specifying routes.
To enable attribute routing you need to set this in your Register
method:
config.MapHttpAttributeRoutes();
That gives you the convenience of setting the routes for each method:
[Route("customers/{customerId}/orders")]
public IEnumerable<Order> GetOrdersByCustomer(int customerId) { ... }
Also, RoutePrefix
allows to avoid repetitively providing the whole path:
[RoutePrefix("api/books")]
public class BooksController : ApiController
{
// GET api/books
[Route("")]
public IEnumerable<Book> Get() { ... }
// GET api/books/5
[Route("{id:int}")]
public Book Get(int id) { ... }
// POST api/books
[Route("")]
public HttpResponseMessage Post(Book book) { ... }
}
EDIT Coming back to your comment:
Have a look at this answer and the way the DefaultHttpControllerSelector
is derived from and filled with some logic:
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Dispatcher;
public class ApiControllerSelector : DefaultHttpControllerSelector
{
public ApiControllerSelector (HttpConfiguration configuration) : base(configuration) { }
public override string GetControllerName(HttpRequestMessage request)
{
// add logic to remove hyphen from controller name lookup of the controller
return base.GetControllerName(request).Replace("-", string.Empty);
}
}
To make this work you then need to specify the custom ApiControllerSelector
in the config like this:
config.Services.Replace(typeof(IHttpControllerSelector),
new ApiControllerSelector(config));