O'Reilly logo

Learning Angular for .NET Developers by Rajesh Gunasundaram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Routing in the ASP.NET Web API

Any request to the Web API is mapped with the HTTP verbs or actions in the controller using routing. Web API 2 introduced an attribute-based routing technique called attribute routing. Attribute routing can be added at the controller level and action level. We can decorate a Web API controller with a Route attribute by passing the template of the URL, as demonstrated in the following code snippet:

[Route("api/[controller]")] 
public class TodosController : Controller 
{    
    // GET: api/todos/pending-only 
    [HttpGet] 
    [Route("pending-only")] 
    public IEnumerable<Todo> GetPendingOnly() 
    { 
    } 
} 

Here, TodosController is decorated by Route with the api/[controller] URL template. This means that if the request is received with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required