-
First check
ExampleHere's a self-contained, minimal, reproducible, example with my use case: import uvicorn
from pydantic import BaseModel
from fastapi import FastAPI
class Item(BaseModel):
name: str
description: str
app = FastAPI()
@app.get("/items")
def create_item(item: Item):
return item
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=5000, debug=True)You can run and test the above code with this CURL request: curl -X GET \
http://localhost:5000/items \
-d '{
"name": "test",
"description": "tester"
}
'DescriptionFastAPI's documentation seems to suggest that GET requests with a body aren't supported: https://fastapi.tiangolo.com/tutorial/body/ However, running the above example it looks like this is supported, although the auto generated documentation misses documenting the parameters of the body. Can this be supported in FastAPI? Our use case is that we need to support a GET method that could contain a sizable amount of data in the request. We don't really want to make this a POST method as the endpoint is only for retrieval and isn't modifying any data. Everything appears to be working for us except the auto generated documentation. Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
|
I don't recall it properly, but I saw an issue talking about it... It seems like Swagger didn't support previously, but they are going to support/or are already supporting. There's an open PR related to what you're talking about, you might want to check: #1626 |
Beta Was this translation helpful? Give feedback.
-
|
Yeah, that's currently supported by FastAPI in recent versions (the current is |
Beta Was this translation helpful? Give feedback.
-
|
I have kind of the opposite issue, in that I have not defined a request body for my GET requests, but swagger is prepopulating it with: This forces me to always remove the request body before executing, when running any API calls through the swagger UI. I've searched for how to hide this, but the only examples I've found so far are for Java applications. EDIT: Please disregard. This was caused by a bad type hint. Instead of |
Beta Was this translation helpful? Give feedback.
-
|
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
Beta Was this translation helpful? Give feedback.
Yeah, that's currently supported by FastAPI in recent versions (the current is
0.62.0), but discouraged, as it's not part of the web standards. And the docs with Swagger UI will probably not show the optional GET body, but curl should work.