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'}
Asked By: Jatin Mehrotra

||

Answers:

Probably duplicated question. Here is another one:

What does the Ellipsis object do?

It is part of Python, not FastAPI

Answered By: Srđan Popić

... (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.

Answered By: marukaz
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.