Introduction to GraphQl for Beginners: Part One (1)

Part one: How GraphQl solves the problem of REST API

As a Full-stack developer, I believe no tool is perfectly better than others. Everything has flaws. Take REST API as an example. Though REST API is popularly used API standards, it has one known problem.

Before jumping into the problem, I am going to discuss some introductory terms.

API

API is the short form of Application Program Interface, which means the way of interaction between programs. Developers develop API on server side so that other applications can requests data through this API.

REST API

REST is the short form of REpresentational State Transfer. It is a set of rules to create API. Look at below image for better understanding,

It seems everything perfect with REST till now. REST API is good as it defines standards to create API. But there is one major issue with REST API.

The Issue with REST API

Let’s talk about the issue now. For example, you developed an API for your awesome blog site. An API (fetching user profile information) is like below,

Suppose, for blog site purposes, you need user information in two places on the website. One place is the User Profile page where the user updates his profile information. Another place is the blog post comment page, where the user image and username are used in a comment card.

You can use the /user-profile API in both places. But in the comment card, you get some unnecessary data like firstname and lastname. To avoid this problem, you can build another API only for comment card like below,

If you have another case where you need only firstname, what will you do? Building another API?

Problem Solved by GraphQl

To solve the issue, GraphQl Comes into play.

#2 Same endpoint- I need id, email

If you look at the above images, you see the endpoint is the same. What I need to do is asking for data that I need. That’s how GraphQl solves the problem of REST API.

The purpose of this blog post is just to discuss how GraphQl is better than REST API. The purpose is fulfilled 🔥. Recommended site of GraphQl — https://graphql.org/.

Don’t forget to follow my Medium Profile to get my latest updates.

Happy Learning

Software Engineer | Professional Scrum Master | Research Enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store