-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add better support for request body access/manipulation #589
Conversation
Codecov Report
@@ Coverage Diff @@
## master #589 +/- ##
======================================
Coverage 100% 100%
======================================
Files 258 264 +6
Lines 6307 6427 +120
======================================
+ Hits 6307 6427 +120
Continue to review full report at Codecov.
|
Awesome @dmontagu ! Thanks a lot! 🎉 🚀 🍰 I think this is sufficiently important to have its own section in the docs, so I moved it. I put it near the end as I consider this quite advanced and it could confuse newcomers. I also added an extra example setting the Thanks again! 🙇♂️ 🌮 |
This pull request introduces a small change to
APIRoute
to make it easier to construct a customapp
attribute in a custom subclass.There is a lot of custom functionality that this change would simplify, but there are two especially important capabilities it adds:
I've added two sections to the "Using the Request Directly" docs showing how to use the changes in this PR to implement both of the above kinds of feature.
There have been many recent github issues that could be better-addressed with this capability.
Related to accessing the body in middleware/exception handlers:
Related to modifying the request prior to handling by FastAPI:
Quoting Tom Christie from encode/starlette#495:
I think using middleware to consume the request body is the obvious (or, perhaps, "naive") way to handle these issues. But that approach is explicitly discouraged, and not supported. So I think the approach described in / supported by this PR is especially valuable.
(This pull request is in lieu of #568, and includes what I think is both the smallest and most important change to
APIRoute
from that pull request.)