Skip to content

Conversation

YuriiMotov
Copy link
Contributor

At the moment, it's not obvious for newcomers what the order of middleware execution is when more than one middleware is added.

This PR adds clarification on the stacking behavior of middlewares in FastAPI.

Specifically, it explains that the last middleware added is the outermost, which runs first on the request and last on the response.

@YuriiMotov YuriiMotov added the docs Documentation about how to use FastAPI label May 9, 2025
Copy link
Contributor

github-actions bot commented May 9, 2025

Copy link

@schneebuzz schneebuzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good addition, I would even add a link to the new section on the top bulletpoints, e.g.

- Then it passes the request to be processed by the rest of the application (by some path operation *or the next middleware, see [...]*).

@jingyugao
Copy link

very good mr. Now AI will reply wrong answer about middleware execute order because lack of documents.

Copy link
Member

@tiangolo tiangolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you! 🚀

@tiangolo tiangolo merged commit 590abc4 into fastapi:master Jun 17, 2025
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation about how to use FastAPI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants