Get the request body of post or get in request #6938
-
|
I can get the request body of the post method in Flask in this way I can also get the request parameters of the get method in the flash API in the following way But I can't find the body in the FastAPI post What should I do?thanks |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
|
Please consult the documentation: https://fastapi.tiangolo.com/tutorial/body/ |
Beta Was this translation helpful? Give feedback.
-
|
The FastAPI documentation covers how to get the body with FastAPI parameters (and dependencies). It's also possible to get the Request |
Beta Was this translation helpful? Give feedback.
-
Can this be implemented in middleware |
Beta Was this translation helpful? Give feedback.
-
What's wrong with this? When I got to the point of getting JSON, the program got stuck. Can't get the data in JSON |
Beta Was this translation helpful? Give feedback.
-
You can take a look at my chat with klaa97, which has the troubles I'm facing now. Thank you. |
Beta Was this translation helpful? Give feedback.
-
The problem is due to a known "issue" or design choice in Starlette (check the related issue here for more details): consuming the request body in a ASGI Middleware is problematic, therefore I suggest you to check out this doc: https://fastapi.tiangolo.com/advanced/custom-request-and-route/#custom-apiroute-class-in-a-router ; by using a custom APIRoute class, it will possible to retrieve the request body (since you'll have the same interface as in a standard path operation) |
Beta Was this translation helpful? Give feedback.
-
thanks |
Beta Was this translation helpful? Give feedback.
-
|
Feel free to close the issue if resolved 👍 |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the help here @klaa97 and @Mause ! 👏 🙇 Thanks for reporting back and closing the issue @mingtiandemeng 👍
|
Beta Was this translation helpful? Give feedback.
Please consult the documentation: https://fastapi.tiangolo.com/tutorial/body/