ASP.NET Core › Endpoint Metadata, Route Constraints & Templates
What is route grouping via MapGroup, and how does it let you apply shared route prefixes, metadata, and filters to a set of related minimal API endpoints?
IntermediateAnswer
MapGroup("/prefix") returns a RouteGroupBuilder that automatically prepends the given prefix to every endpoint mapped within it, and any metadata, authorization requirements, or filters applied to the group (via .RequireAuthorization(), .AddEndpointFilter(), .WithTags()) automatically apply to all endpoints in that group, reducing repetition for a cohesive set of related routes.
var productsGroup = app.MapGroup("/api/products")
.RequireAuthorization()
.WithTags("Products");
productsGroup.MapGet("/", GetAll); // -> /api/products, requires auth
productsGroup.MapGet("/{id}", GetById); // -> /api/products/{id}, requires auth
productsGroup.MapPost("/", Create); // -> /api/products, requires authReal-world example A minimal API organizes all product-related endpoints under one MapGroup call, applying shared authorization and Swagger tagging once at the group level instead of repeating the same configuration on every individual endpoint registration.