Skip to content

Support request bodies for GET requests? #1691

@gjdanis

Description

@gjdanis

First check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.
  • After submitting this, I commit to one of:
    • Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
    • I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.
    • Implement a Pull Request for a confirmed bug.

Example

Here'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"
}
'

Description

FastAPI'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

  • OS: [e.g. Linux / Windows / macOS]: Windows
  • FastAPI Version [e.g. 0.3.0]: 0.54.1
  • Python Version: 3.8.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions