Replies: 6 comments
-
Taken from https://fastapi.tiangolo.com/tutorial/body/#create-your-data-model |
Beta Was this translation helpful? Give feedback.
-
Also, if you just want your request to require some kind of json body without defining a pydantic model, you can define it like this: from fastapi import FastAPI
app = FastAPI()
@app.post("/my-route")
async def my_post_route(request_data: dict) -> dict:
return {"posted": request_data} |
Beta Was this translation helpful? Give feedback.
-
I thought using an ellipsis would make the body parameter mandatory as well, just like query parameters: https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#make-it-required. If not, I would consider this a bug, or at least inconsistent behavior 🙂 Maybe it does not work as expected in this particular case because your |
Beta Was this translation helpful? Give feedback.
-
I understand that it doesnt make sense as I am using starlette Requests here. Since then the code has been refactored to use a pydantic model. Thank you |
Beta Was this translation helpful? Give feedback.
-
Thank you for the response. This was required for a quick POC where I couldnt finalize the pydantic model initially. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the help here everyone! 🍰 And thanks @vrjram for reporting back and closing the issue 👍 |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have a code segment as below:
But in the API spec, the request body is not defined as a mandatory field. Infact there is no body.
Is there any additional steps required to make this mandatory. Please advice.
Thank you
Beta Was this translation helpful? Give feedback.
All reactions