question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow JSON payload for GET calls

See original GitHub issue

First check

  • [x ] I added a very descriptive title to this issue.
  • [x ] I used the GitHub search to find a similar issue and didn’t find it.
  • [ x] I searched the FastAPI documentation, with the integrated search.
  • [ x] I already searched in Google “How to X in FastAPI” and didn’t find any information.
  • [x ] I already read and followed all the tutorial in the docs and didn’t find an answer.
  • [ x] I already checked if it is not related to FastAPI but to Pydantic.
  • [ x] I already checked if it is not related to FastAPI but to Swagger UI.
  • [ x] I already checked if it is not related to FastAPI but to ReDoc.
  • [x ] After submitting this, I commit to:
    • Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
    • Or, 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:

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

![Screen Shot 2020-09-02 at 2 00 10 PM](https://user-images.githubusercontent.com/5025518/92019556-ca7cbf00-ed24-11ea-84d6-52dbc18a8aec.png)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ycdcommented, Dec 30, 2020

@stevesuh the code piece works when you send a request with cURL

curl -X GET "http://127.0.0.1:8000/foo/bar" -d "{\"countryID\":1}"

So basically FastAPI allows request body with GET operations, however, Swagger UI doesn’t support it.

They are also very strict about not supporting it.

See: https://github.com/swagger-api/swagger-ui/issues/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.

2reactions
ycdcommented, Sep 3, 2020

@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… 🤕

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I send JSON Payload to the server?
To send the JSON payload to the server, you need to enclose the JSON data in the HTTP request body and indicate the...
Read more >
For Restful API, can GET method use json data? [duplicate]
To answer your question, yes you may pass JSON in the URI as part of a GET request (provided you ...
Read more >
API Call to website--Can I put the JSON Body here?
In the Payload tab of the Downloads tool I am using the "Use Following for Query String/Body" and placing the Body of the...
Read more >
How to send payload to http GET request in mule 3
How to call HTTP GET method in mule 3 by passing some json payload. ... Some server allow request body in GET Request...
Read more >
Tutorial: Create a Calc REST API with two AWS service ...
... Integration 2: Create a POST method with a JSON payload to call the Lambda function; Integration 3: Create a GET method with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found