liveBook · Manning

Request pipeline

As explained in Building Web APIs with ASP.NET Core

The HTTP request pipeline is the ordered sequence of ASP.NET Core middleware through which an HTTP request and response are processed.

The HTTP request pipeline is the ordered chain of ASP.NET Core middleware that processes a request and produces a response. Each component can pass control onward or return a response immediately, stopping later components from running. section 1.2.1

Configure the pipeline with these practical rules:

  • Register middleware in processing order; ASP.NET Core evaluates it first in, first out. section 1.2.1
  • Place potentially terminal middleware before terminal middleware, because terminal components always end processing. section 1.2.2
  • Use HTTPS redirection, authorization, static-file handling, or endpoint mapping according to the responsibility each component provides. section 1.2.1
  • Treat Run as fully terminal and normally the final pipeline operation. section 1.2.2

A typical Program.cs pipeline

Build the application, enable Swagger only in development, redirect HTTP to HTTPS, enable authorization, map controllers, and finish with app.Run(). The sequence makes the request path explicit while keeping service registration separate from pipeline configuration. section 1.2.2

var builder = WebApplication.CreateBuilder(args);    #1
 
// Add services to the container.
 
builder.Services.AddControllers();                   #2
// Learn more about configuring Swagger/OpenAPI
// at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();          #2
builder.Services.AddSwaggerGen();                    #2
 
var app = builder.Build();                           #3
 
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();                                #4
    app.UseSwaggerUI();                              #4
}
 
app.UseHttpsRedirection();                           #4
 
app.UseAuthorization();                              #4
 
app.MapControllers();                                #4
 
app.Run();                                           #5

Inspect the complete Program.cs listing to see service registration, application construction, environment-specific middleware, endpoint mapping, and the terminal Run call together. section 1.2.2

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Explains middleware responsibilities, ordering, short-circuiting, and terminal behavior without descending into implementation internals.
Examples
Uses HTTPS redirection, Swagger, authorization, controller mapping, static files, and app.Run() as pipeline examples.
What you can do after
Operate/configure it by arranging ASP.NET Core middleware and identifying components that terminate request processing.
How it connects
Connects middleware with dependency injection, authorization, services, controllers, minimal APIs, and endpoint mapping.

Also explained in

Compare how 2 books explain request pipeline →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.