-
First check
ExampleHere's a self-contained minimal, reproducible, example with my use case: from fastapi import FastAPI
app = FastAPI()
class Sample(BaseModel):
countryId: int
@router.get("/foo/bar",
response_model=Sample)
def get_sample(sample: Sample):
return {"Hello": "World"}
### Description
* Open the browser and call the GET endpoint `/foo/bar`.
* Pass in JSON body with `{"countryId": 1}`.
* TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
### The solution you would like
It doesn't throw the TypeError and allows GET calls to pass in JSON payloads
### Environment
* OS: [e.g. Linux / Windows / macOS]: macOS
* FastAPI Version [e.g. 0.3.0]: 0.60.1
* Python version:
3.7.7
### Additional context
 |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
|
It's not something we'll be able to solve. We have already done everything that we could. You can follow the discussions and solution already merged: |
Beta Was this translation helpful? Give feedback.
-
|
The HTTP GET method requests a representation of the specified resource. Requests using GET should only retrieve data.
The HTTP specification says in section 4.3
|
Beta Was this translation helpful? Give feedback.
-
|
@ycd The HTTP specification your using is from 1991. The updated one is RFC 7231 where it is allowed to include a body. So generally it is allowed but discouraged. |
Beta Was this translation helpful? Give feedback.
-
|
@ArcLightSlavik thanks, just read that publication ,actually you were right, in practice it's fine but in theory it's not a good idea i think.. 🤕 |
Beta Was this translation helpful? Give feedback.
-
|
An update to this issue, i found this when looking for something else,
since FastAPI is based on OpenAPI specification i do not think we are able to this. |
Beta Was this translation helpful? Give feedback.
-
That's true for OpenAPI 3.0, but seems to be changed in 3.1 as this PR suggests. The same change was removed from 3.0 only because it did't fit the semantics of a patch release According to the PR, 3.1 will read as follows, which is in-line with RFC 7231.
|
Beta Was this translation helpful? Give feedback.
-
|
@stevesuh the code piece works when you send a request with cURL So basically FastAPI allows request body with They are also very strict about not supporting it. See: swagger-api/swagger-ui#2136 If you want you can open another issue in Swagger UI's repository but FastAPI can not do anything about this topic since your issue is completely about the Swagger UI. |
Beta Was this translation helpful? Give feedback.
-
|
I consider the issue resolved then. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the help here everyone! 👏 🙇 Thanks for reporting back and closing the issue @stevesuh 👍
|
Beta Was this translation helpful? Give feedback.

It's not something we'll be able to solve. We have already done everything that we could.
You can follow the discussions and solution already merged:
To summarize: