Web api custom routing

asp.net-mvc, asp.net-mvc-4, asp.net-web-api

Solution

You could change your web api route definition to allow passing an action name:

routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{action}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

And then:

public class QuotaController : ApiController
{
    public void Increment()
    {
        ...
    }

    public void Decrement()
    {
        ...
    }
}

Problem

I have a Controller called QuotaController, and i can access it via httprequests, like this: localhost:12345/quota/ What i want is to put an endpoint somewhere so i can access it like: localhost:12345/quota/increment or localhost:12345/quota/decrement How can this be done?

Original source