Build APIs Like Facebook – Use GraphQL
GraphQL allows us to structure the interaction between frontend and backend and allows for retrieving data, writing data and getting notified. To structure the interaction, GraphQL offers a declarative, typed query language for APIs and a runtime for building GraphQL APIs.
GraphQL is a query language for APIs. The language allows us to structure the interaction between frontend and backend. The language provides primitives for specifying the data served by the API, retrieving data, writing data and getting notified when data changes.
GraphQL allows us to define and describe our data structures. For this purpose, GraphQL provides a typed schema language. We specify custom types for the data served by the API. A GraphQL schema is created by defining types and fields on those types, then providing functions for each field on each type.
What about REST? Distributed systems in general are built with architectural styles of RPC, SOAP or REST, but when it comes to APIs, REST is the main paradigm. For a long time, REST was even thought to be the only accepted architectural style for building APIs. Now there is an alternative: GraphQL. That does not mean that GraphQL replaces REST and pushes it off the stage. There are still good reasons to choose a RESTful API design. GraphQL widens the spectrum of available architectural styles.
GraphQL is neither the same as REST, nor is GraphQL an extension of REST nor is GraphQL an improved version of REST. GraphQL and REST are competing architectural styles for APIs, with different philosophies. Each philosophy has its strong and its weak points. Looking at REST and GraphQL, there are a number of commonalities and major differences. When building a new API, it is a case-by case decision to go with REST or GraphQL. We can show situations in which the strengths of each approach can shine.
The API-University Series is a modular series of books on API-related topics. Each book focuses on a particular API topic, so you can select the topics within APIs, which are relevant for you.
Keywords: GraphQL, API, REST, Design, Web Service, Mobile App, React
Available December 2017.
Get a Discount Code Now:
Get the Book
Title: GraphQL API Design – And How It Compares to REST API Design