What is REST API ?
REST is an architectural style and a design for network-based software architectures.It stands for REpresentational State Transfer. The basic idea of REST is treating objects on the server-side (as in rows in a database table) as resources than can be created or destroyed.
REST works on principles below as listed in dissertation presented by Roy Fielding here [1]. The desertion is worth reading to get good insight into the REST working.
Client–server , Stateless, Cacheable, Uniform interface, Layered system, Code on demand (optional)
What is GraphQL ?
REST APIs have shown to be too inflexible to keep up with the rapidly changing requirements of the clients that access them. GraphQL was developed to cope with the need for more flexibility and efficiency! It solves many of the shortcomings and inefficiencies that developers experience when interacting with REST APIs.
Some of the advantages of Graphql over REST
- Data fetching : Only fetch what you want in single network call. For example, a social networking app. For a REST api we will require multiple API calls to fetch User’s posts and information about the users who commented on that post. With Graphql the client the information / fields that it wants and the Grpahql server provisions it with a single network between client and graphql server. Also note that with REST api there is no control over data returns there could be less or more information the response.
- Schema : GraphQL uses a strong type system to define the capabilities of an API. All the types that are exposed in an API are written down in a schema using the GraphQL Schema Definition Language (SDL). Once the schema is defined, the teams working on frontend and backends independently decreasing development/testing time
More on the advantages can be followed through this blog here [2].
References :
Comments
Post a Comment