liveBook · Manning

Endpoint

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

An endpoint is an addressable application operation associated with a URL pattern that receives a dispatched request and returns a response.

An endpoint defines how an application generates a response for a request. In an ASP.NET Core minimal API, you map an endpoint to a URL path and an HTTP verb. A browser request to the path / normally uses GET; an endpoint mapped to that combination can return “Hello World!”. section 3.6

Start with two GET endpoints

After building a WebApplication, call app.MapGet("/", () => "Hello World!") to return plain text at /. Add app.MapGet("/person", () => new Person("Andrew", "Lock")) to return a Person record as JSON at /person. Call app.Run() to start listening for requests. section 3.6 section 3.7

Mapping an endpoint and running it are separate steps. RoutingMiddleware selects an endpoint whose route matches the incoming request; EndpointMiddleware executes the selection. If no route template matches, EndpointMiddleware does not generate a response. Middleware between those two stages can inspect the selected endpoint before it runs. section 6.2 section 6.5

Figure 6.3 Endpoint routing uses a two-step process. The RoutingMiddleware selects which endpoint to execute, and the EndpointMiddleware executes it. If the request URL doesn’t match a route template, the endpoint middleware won’t generate a response.
CH06_F03_Lock3

The diagram follows a request through endpoint selection and execution, including the case where no route matches. section 6.2

Endpoints are not limited to minimal APIs: health checks and Razor Pages can also be registered with WebApplication. Route templates describe the URLs an endpoint can match, and route parameters let one endpoint handle multiple URLs. Choose routes carefully because they form a public surface of an API. section 6.2 section 6.5

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

How deep it goes
Explains endpoint mapping, handlers, route matching, and selection versus execution; extends basic examples to route templates and parameters.
Examples
Uses a plain-text GET response at /, a JSON Person response at /person, and mapped health-check and Razor Page endpoints.
What it assumes
Introduces HTTP verbs and URL paths from basic browser requests before adding endpoint mapping.
What you can do after
Build it from scratch by mapping GET handlers on WebApplication and running the app to serve their responses.
How it connects
Connects endpoints to HTTP verbs, route templates, minimal APIs, middleware, Razor Pages, and MVC controllers.

Also explained in

Compare how 26 books explain endpoint →

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.