Aakanksha Choudhary
Aakanksha Choudhary

Reputation: 625

Why are GraphQL queries POST requests even when we are trying to fetch data and not update/submit new data?

I am using Postman to fetch data from my server and when I use a REST call it is a GET request but when I use a GraphQL API call, it needs to be a POST request. Why is it so?

Upvotes: 30

Views: 9786

Answers (1)

Daniel Rearden
Daniel Rearden

Reputation: 84687

The GraphQL spec is itself transport-agnostic, however the convention adopted by the community has been to utilize POST requests. As pointed out in the comments, some libraries support GET requests. However, when doing so, the query has to be sent as a URL query parameter since GET requests can't have bodies. This can be problematic with bigger queries since you can easily hit a 414 URI Too Long status on certain servers.

The best practice is to always utilize POST requests with a application/json Content-Type.

Upvotes: 52

Related Questions