Route Groups, Parameters & Validation
Organize endpoints with MapGroup, bind route/query/body parameters, and validate with data annotations.
Route Groups for Organization
MapGroup() (introduced in .NET 7) lets you group related endpoints under a common prefix and apply shared configuration — middleware, auth policies, tags — without repeating it on each endpoint.
Creating a Route Group
Call app.MapGroup("/api/products") and then map endpoints on the returned group. The prefix is automatically prepended to all routes.
var products = app.MapGroup("/api/products").WithTags("Products");
products.MapGet("/", GetAll);
products.MapGet("/{id}", GetById);
products.MapPost("/", Create);
products.MapPut("/{id}", Update);
products.MapDelete("/{id}", Delete);
// Routes: /api/products, /api/products/{id}All lessons in this course
- Creating Your First Minimal API
- Route Groups, Parameters & Validation
- Middleware & Filters in Minimal APIs
- OpenAPI, Versioning & Deployment