Repository navigation
Add better support for request body access/manipulation - #589
Merged
Merged
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.
|
dmontagu
commented
Oct 4, 2019
Member
|
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a small change to
APIRouteto make it easier to construct a customappattribute 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 Kludex/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
APIRoutefrom that pull request.)