Zoltan Varadi
Zoltan Varadi

Reputation: 2488

Web api custom routing

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?

Upvotes: 4

Views: 2499

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039498

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()
    {
        ...
    }
}

Upvotes: 5

Related Questions