0Pricing
C# Academy · Lesson

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

  1. Creating Your First Minimal API
  2. Route Groups, Parameters & Validation
  3. Middleware & Filters in Minimal APIs
  4. OpenAPI, Versioning & Deployment
← Back to C# Academy