FASTAPI: what is`(..)` in the Body(…) while reading from a post request?
Question:
I am trying to read body from my POST request using FastAPI.
However i am not able to understand what (...)
argument for the Body function
Here is my code :
@app.post('/createPosts')
def create_post(payload: dict = Body(...)):
print(payload)
return {'message': 'succesfully created post'}
Answers:
Probably duplicated question. Here is another one:
What does the Ellipsis object do?
It is part of Python, not FastAPI
...
(Ellipsis) was the way of declaring a required parameter in FastAPI.
However, from 0.78.0, you can just omit the default value to do that.
See release note and documentation for details.
I am trying to read body from my POST request using FastAPI.
However i am not able to understand what (...)
argument for the Body function
Here is my code :
@app.post('/createPosts')
def create_post(payload: dict = Body(...)):
print(payload)
return {'message': 'succesfully created post'}
Probably duplicated question. Here is another one:
What does the Ellipsis object do?
It is part of Python, not FastAPI
...
(Ellipsis) was the way of declaring a required parameter in FastAPI.
However, from 0.78.0, you can just omit the default value to do that.
See release note and documentation for details.