Mid
ASP.NET Core
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.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png