DEV Community

Usman Pervez
Usman Pervez

Posted on

What is Request Pipeline?

The request pipeline is simply:

The path an HTTP request follows inside ASP.NET Core before a response is returned.

Think of it like a chain of steps.

When a user sends a request like:

https://yourwebsite.com/api/users
Enter fullscreen mode Exit fullscreen mode

that request does NOT directly go to the controller.

Instead, it passes through multiple stages first.


How the pipeline actually works

Imagine this flow:

Client → Server → Middleware 1 → Middleware 2 → Middleware 3 → Controller → Response → Back through middleware → Client
Enter fullscreen mode Exit fullscreen mode

So every request must pass through middleware before reaching the controller.

And every response passes back through the same pipeline.


Real example of what happens internally

When someone opens your API endpoint:

GET /api/users
Enter fullscreen mode Exit fullscreen mode

ASP.NET Core processes it like this:

  1. Request reaches the server
  2. Authentication middleware checks if the user is logged in
  3. Authorization middleware checks if the user has permission
  4. Routing middleware finds which controller should handle the request
  5. Controller executes the logic
  6. Response is created
  7. Response travels back through middleware
  8. Response is sent to the browser

This entire flow is called the request pipeline.


Most fresh developers think:

User → Controller → Response
Enter fullscreen mode Exit fullscreen mode

But real flow is:

User → Middleware → Routing → Controller → Middleware → Response

Enter fullscreen mode Exit fullscreen mode

What is Middleware (the core of the pipeline)

Middleware is a small piece of code that:

  • Receives a request
  • Can process it
  • Can stop it
  • Can modify it
  • Or pass it to the next step

Example:

Authentication middleware:

  • If token is valid → continue
  • If token is invalid → stop the request

So middleware controls the entire request flow.


Where the pipeline is written in a .NET project

Open this file:

Program.cs
Enter fullscreen mode Exit fullscreen mode

You’ll see lines like this:

app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
Enter fullscreen mode Exit fullscreen mode

These lines define the order of the request pipeline.
And the order is extremely important.


I Hope you get the concept, Thank You.

Top comments (0)