GraphQL the HTTP Request and Response format

Hi, in this post we are going to understand how GraphQL works with HTTP.

Note: last GraphQL chapter was GraphQL course querying using GraphQL playground

Let run again our sever and go to the browser and open the network tab:

And then if we execute our current query again – click in play button and lets examine the network:

Then click on that request:

Then we are going see more information about the REQUEST, like the RequestURL that is the same as our browser url:

And also we can see that the method is POST, so this is a difference compare to REST API so with GraphQL we alway make POST request even though this is to get data.

Then if we look the Request Headers

And if we see the content type: is application/json that means that the client is posting some “json” to the server

If we look to the Request payload is in fact a Json object with 3 properties:

The important one is the query property that is the same as we have in the PlayGround except that the new line has been escape in the Json string:

Now let’s look the RESPONSE from the server, so the response is “200” that means that the response was successful.

If we look the Response Headers we can see how the Content-Type is also ‘application/json‘ so the request and the respond will be all the time json format.

And finally if we look the response: we can see how the response is in Json format and also if you see the playground you can see also the same Json object

So, request in Json format and response also is in Json format.

By Cristina Rojas.