liveBook · Manning

Terminal middleware

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

Terminal middleware is a middleware component that stops further pipeline processing by generating and returning a response.

Terminal middleware short-circuits the ASP.NET Core middleware pipeline by generating and returning a response. Later middleware, including endpoint middleware, never receives that request. section 4.1

Requests normally move forward through middleware until a component creates a response. That response then travels backward through the earlier components before reaching the web server, so middleware can run logic on both directions. section 4.1

Returning the current time

A small custom terminal component can return the current time as plain text whenever the application receives a request. This response ends processing rather than flowing to an endpoint. section 31.1

Use terminal middleware for small responses that do not need endpoint routing, such as a welcome page or Swagger response. Prefer endpoint routing when it provides the needed behavior; use custom middleware for occasional specialized requirements. section 31.1

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

How deep it goes
Explains short-circuiting, reverse response flow, and practical use cases, but stops short of implementing the three custom middleware approaches.
Examples
Uses authorization denial, Swagger, a welcome page, and a current-time plain-text response as concrete terminal responses.
What it assumes
Assumes familiarity with middleware pipelines and endpoint processing while explaining short-circuiting from the request-response flow.
What you can do after
Apply it via ASP.NET Core middleware to stop request processing and return a specialized response.
How it connects
Connects terminal middleware with middleware pipelines, endpoint routing, authorization middleware, and the chain-of-responsibility pattern.

Also explained in

Compare how 2 books explain terminal middleware →

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.