0

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'}
Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67
  • It's the python built-in constant [`Ellipsis`](https://docs.python.org/3/library/constants.html#Ellipsis). I'm surprised that I can't find a duplicate for this question, maybe someone else can. – myrtlecat Feb 03 '22 at 02:25
  • 1
    Even i couldn't find a duplicate :(, okay its a built-in constant but what is the use of it? it throws error if i omit it – Jatin Mehrotra Feb 03 '22 at 02:27
  • I think [this](https://stackoverflow.com/questions/772124/what-does-the-ellipsis-object-do) might be the aforementioned duplicate, and [this answer](https://stackoverflow.com/a/66666228/16450169) discusses FastAPI specifically – 0x263A Feb 03 '22 at 02:37
  • even though it explain `what` is Ellipsis but it doesnt say `why`? Also it doesnt even mention the context in using with FASTAPI, post request – Jatin Mehrotra Feb 03 '22 at 02:42

2 Answers2

3

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

marukaz
  • 64
  • 2
-1

Probably duplicated question. Here is another one:

What does the Ellipsis object do?

It is part of Python, not FastAPI

Srđan Popić
  • 1,191
  • 13
  • 25