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 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 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.
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?
To solve the issue, GraphQl Comes into play.