#GraphQL #APIs #JSON #REST …GraphQL is a query language for API and a server-side runtime for executing queries by using a type system define for any data. GraphQL isn’t tied to any specific database or storage engine and is instead backed by your existing code and data. GraphQL is a new way to think about building and querying APIs. Rather than construct several REST requests to fetch data that you’re interested in, you can often make a single call to fetch the information you need. Client applications who speak GraphQL can query the schema within its capabilities. This approach decouples clients from servers and allows both of them to evolve and scale independently.

 

A GraphQL request can be either a query (read operation) or a mutation (write operation). For both cases, the request is a simple string that a GraphQL service can interpret, execute, and resolve with data in a specified format. The popular response format that is usually used for mobile and web applications is the JavaScript Object Notation.

Why GraphQL?

  • Single-round trip: All data is fetched in a single round-trip vs. multiple-round trips in REST. In our example above, for a REST client to get all products in each category, it would need to first fetch the store’s categories from one API endpoint, and then for each category fetch their products from another API endpoint.
  • No over-fetching: A client has full control of fetching only data that it needs vs. in REST API, on the server-side we have to balance between minimizing multiple round-trips (‘n+1’ problem) and over-fetching; we can eliminate ‘n+1’ problem we described above if we make the API that returns store categories, also return all products, but another set of clients that just wants categories of a store will be over-fetching.
  • One endpoint to access your data- Single API endpoint to server all data needs
  • Retrieve only the data your client needs in a single request (flexibility)
  • No need to tailor endpoints for your views
  • No versioning

 

Share This :

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>