Mid ASP.NET Core

Routing conventions in Web API (attribute routing, route?

templates)

  • Attribute Routing (Preferred):

[Route("api/products")]

[ApiController]

public class ProductsController : ControllerBase {

[HttpGet("{id}")]

public IActionResult Get(int id) { ... }

  • Route Templates:

Use placeholders like {id}, constraints like {id:int}.

You can also define route prefixes at controller level and use relative routes

in actions.

More from ASP.NET Core Tutorial

All questions for this course