attribute routing
Declaring a controller's routes with attributes such as [Route("api/products")] and [HttpGet("{id:int}")] on the class and its actions.
In more detail
Attributes on the class set a prefix, and attributes on each action add the rest of the path and the HTTP method. The URL shape then sits right next to the code that handles it.
Related terms
- routing — Choosing which piece of code handles a request, based on its method and path, such as GET /users/42.
- controller — In ASP.NET Core, a class deriving from ControllerBase that groups related HTTP endpoints as methods called actions.
- attribute — A tag in square brackets, such as [Required] or [HttpGet], that attaches extra information to code for the compiler or framework to read.
- HTTP method — The verb at the start of a web request that says what the client wants, such as GET to read or POST to create.
Taught in
- Building Routes with Controllers — Modern .NET Core, C# & Enterprise Microservices
- Comparing Controllers and Minimal APIs — Modern .NET Core, C# & Enterprise Microservices