HTTP Response
Regardless of the request method, the response should be returned in the body of the response in JSON format. The payload contains,
- data: Contains the data of the GraphQL query execution.
- errors: Contains an array of error objects if any errors occurred during execution.
Response:
{
"data": { },
"errors": [ ]
}
Serving GraphQL over HTTP
HTTP or Hypertext Transfer Protocol, is the foundation of Web communication. Being a stateless protocol, each request from a client to the server is independent and doesn’t retain information about past requests. GraphQL is a query language for APIs and a runtime for executing those queries.
Unlike traditional REST APIs with fixed endpoints and predefined structures, GraphQL allows clients to request the specific data they need on the same endpoint.
One common way to serve GraphQL is over HTTP, providing an efficient and flexible means of communication between client and server. In this article, we’ll explore how we can use the HTTP protocol to serve GraphQL and how it differs from traditional RESTful approaches.