liveBook · Manning

RouteGroupBuilder

As explained in ASP.NET Core in Action, 3e

RouteGroupBuilder is the ASP.NET Core builder type returned for configuring a route group and its shared endpoint conventions.

RouteGroupBuilder is returned by MapGroup() and organizes related minimal API endpoints under a shared route prefix and shared endpoint conventions. section 5.5

Use a RouteGroupBuilder to reduce repeated route and filter configuration:

  • Call app.MapGroup("/fruit") to apply /fruit to every endpoint created on the returned builder. section 5.5
  • Call the same Map* extension methods on the group as on WebApplication. section 5.5
  • Call AddEndpointFilter() once on the group to apply a filter to all endpoints it contains. section 5.5 section 5.6
  • Nest groups to combine prefixes, such as /fruit followed by /citrus; use / when grouping without adding a prefix. section 5.5

Group fruit endpoints and validation

RouteGroupBuilder fruitApi = app.MapGroup("/fruit"); RouteGroupBuilder fruitApiWithValidation = fruitApi.MapGroup("/") .AddEndpointFilter(ValidationHelper.ValidateIdFactory); fruitApiWithValidation.MapGet("/{id}", (string id) => ...); fruitApiWithValidation.MapPost("/{id}", (Fruit fruit, string id) => ...); section 5.5

Figure 5.11 Using route groups to simplify the definition of endpoints. You can create a route group by calling MapGroup() and providing a prefix. Any endpoints created on the route group inherit the route template prefix, as well as any filters added to the group.
CH05_F11_Lock3

See how a group supplies a shared route-template prefix and inherited endpoint filters. section 5.5

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains creation, inherited mappings and filters, nested prefixes, and prefixless grouping with practical endpoint examples.
Examples
Uses a fruit API with /fruit endpoints, nested validation grouping, and a reusable ID-validation filter.
What it assumes
Assumes WebApplication and minimal API endpoint mapping, while demonstrating group behavior through a small fruit API.
What you can do after
Apply MapGroup(), Map* methods, and AddEndpointFilter() to remove repeated route and filter configuration.
How it connects
Connects minimal APIs with route groups, route prefixes, endpoint filters, and nested groups.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.