liveBook · Manning

Endpoint routing

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

Endpoint routing is the ASP.NET Core routing system that separates request endpoint selection from endpoint execution in middleware.

Endpoint routing separates choosing an endpoint from executing it in the ASP.NET Core middleware pipeline. It supports minimal APIs, Razor Pages, MVC, and other middleware through one routing system. section 6.2 section 14.0

A request passes through two routing stages:

  • RoutingMiddleware selects the registered endpoint that matches the request. section 6.2
  • EndpointMiddleware executes the selected endpoint, typically near the end of the middleware pipeline. section 6.2
  • Middleware placed between these stages can inspect the selected endpoint; middleware placed before routing cannot. section 6.2

Registering several endpoint types

A WebApplication can register a minimal API endpoint with MapGet, a health-check endpoint with MapHealthChecks, and Razor Pages with MapRazorPages. A request whose URL matches a route template reaches the corresponding endpoint; an unmatched URL does not produce a response from endpoint middleware. section 6.2

Listing 6.1 Registering multiple endpoints with WebApplication
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
 
builder.Services.AddHealthChecks();           #1
builder.Services.AddRazorPages();             #1
 
WebApplication app = builder.Build();
 
app.MapGet("/test", () => "Hello world!");    #2
app.MapHealthChecks("/healthz");              #3
app.MapRazorPages();                          #4
 
app.Run();

Use the listing to compare endpoint registration for minimal APIs, health checks, and Razor Pages in one small application. section 6.2

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

How deep it goes
Explains endpoint selection, execution, registration, and middleware visibility, while deferring detailed Razor Pages and MVC routing customization.
Examples
Demonstrates MapGet, MapHealthChecks, MapRazorPages, matching route templates, and middleware placement around routing.
What you can do after
Apply endpoint routing by registering endpoints and placing middleware according to whether it needs the selected endpoint.
How it connects
Ties middleware pipelines to minimal APIs, Razor Pages, MVC, authorization, route templates, and URL generation.

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.