Skip to main content

GraphQL vs Rest API



Article by Karthikeyan




RESTful: (stands for Representational State Transfer, REST for short) At this point in time, is the most common choice among most devs. By virtue, they’re easy to implement, they’re stateless, and they return JSON data (although you could use XML as well).

GraphQL: On the other hand, is a query language that Facebook developed to make it easier for their mobile apps to query large amounts of data without making endless requests to the backend. It’s a potent and different approach from the RESTful way.

The core difference between GraphQL and REST APIs is that GraphQL is a specification, a query language, while REST is an architectural concept for network-based software.

REST has had limitations like multiple network requests and overfetching data. To overcome these, Facebook developed GraphQL as an open-source data query and manipulation language for APIs.

One of the most common limitations of REST out-of-the-box is that of overfetching and underfetching. This happens because the only way for a client to download data is by hitting endpoints that return fixed data sets.

Overfetching means getting more information than you need. With GraphQL, you can “have it your way” by describing exactly how you want

GraphQL can be organized in terms of a schema, whereas REST can be arranged in terms of endpoints. It uses metadata for query validation, whereas REST does not have machine-readable metadata cacheable.


Stateless

REST APIs are stateless, meaning that calls can be made independently of one another, and each call contains all of the data necessary to complete itself successfully.

Instead, each call has the necessary data in itself, such as the API key, access token, user ID, etc. This also helps increase the API’s reliability by having all of the data necessary to make the call, instead of relying on a series of calls with server state to create an object, which may result in partial fails.


Apollo Server and GraphQL

Apollo Server is a popular open source implementation of the GraphQL spec. Using the Apollo platform you can build, query, and manage your data graph by connecting to data sources or external APIs.

The platform consists of a JavaScript GraphQL server where you can define your schema and resolver functions. It also consists of a JavaScript Apollo client component that can be used with React, Angular, or Vue frameworks. There is also support for iOS and Android client components.

The Apollo client has features that can directly update the UI components when query results arrive or change and declaratively define the queries from the UI components.



Conclusion:

Organizations around the world are questioning their API technology choices and they are trying to find out if migrating from REST to GraphQL is best for their needs.

GraphQL is a perfect fit when you need to expose complex data representations, and when clients might need only a subset of the data, or they regularly perform nested queries to get the data they need.

As with programming languages, there is no single winner, it all depends on your needs.

You can mix and match REST and GraphQL depending on your needs, and sometimes it’s the best thing to do.


Comments

Popular posts from this blog

What is Micro Frontends Part -1

The term Micro Frontends first came up in ThoughtWorks Technology Radar at the end of 2016. It extends the concepts of micro services to the frontend world. The current trend is to build a feature-rich and powerful browser application, aka single page app, which sits on top of a micro service architecture. Over time the frontend layer, often developed by a separate team, grows and gets more difficult to maintain. That’s what we call a Frontend Monolith . The idea behind Micro Frontends is to think about a website or web app as a composition of features which are owned by independent teams. Each team has a distinct area of business or mission it cares about and specialises in. A team is cross functional and develops its features end-to-end, from database to user interface. Monolithic Frontends Organisation in Verticals Top resources for you to learn more about Micro frontends: Server-side rendering micro-frontends – the architecture . : This blog series explores how to implement micro

Things to consider when adopting Cloud Computing

    If you are someone who is new cloud computing and is deciding to adopt cloud computing, there are several factors you have to consider. Define the role of Cloud :  Are you looking to host your website or a mobile app or you just require storage space for your files.  Business flows and Priorities of the Solution :  At what point, does your cloud solution fit in. Do I already have a system which I need to upgrade. Find the priorities of the system of your business. Need for Integrations with Internal and External systems :  Based on your application needs, we need to figure out the Internal and External services that is essential part or something you cannot replace with your new cloud solution. Once we identify these sub systems and find a possible way to work with your Cloud Framework. Financials of running the solution:  Running a cloud deployment can be cost effective or a costly affair, based on how it is setup. Different services have different costing parameters like bandwidt

Vital Resources for Learning Kubernetes

Kubernetes (also known as k8s or “kube”) is an open source container orchestration platform that automates many of the manual processes involved in deploying, managing, and scaling containerized applications. Kubernetes is a complicated beast. There are many moving parts under the hood. Simplifying Container orchestration isn’t easy Here are 10 Vital Resources that will make you a Kubernetes master in no time 1. A Beginner’s Guide to Kubernetes A comprehensive introduction to Kubernetes architecture. 2. A Guide to the Kubernetes Networking Model   An in-depth run-through of Kubernetes networking.  3. Amazon EKS Best Practices Guide for Security   This guide provides advice about protecting information, systems, and assets that are reliant on EKS while delivering business value through risk assessments and mitigation strategies. 4. Introduction to Using Google Kubernetes Engine; Explain Like I’m Five!   Creating your first managed Kubernetes cluster on Google Kubernetes Engine using Te