What makes an API effective? Is it its performance, documentation, or developer experience? In this article, I will explain the difference between GraphQL and REST API, two of the most popular request-response APIs. We will compare them to see what makes them different, but let's start by defining an API first.
What is an API?
An API (Application Programming Interface) is a set of rules and protocols that defines how computers communicate with each other.
By using APIs, different applications can access the functionality of a software library or expose data and services for developers or businesses to use. The application that accesses the resource is referred to as the client, and the application, which contains the resources, is called the server. Now that we have defined APIs, let's explore them in more detail.
What is REST?
REST stands for Representational State Transfer, an architectural pattern for requesting and retrieving data over HTTP. REST is a set of rules for building web applications or an architecture style used to design network applications.
Web services are made such that resources are stored on a server in different states. When there's a request by a user, the information received by the user represents the state of the resource, not how the resource is stored on the server.
The representation of the State, which is the resource data, can be in different formats, either in JSON, HTML or XML, etc. JSON is used the most for sending and receiving data because it’s easy to understand.
REST API helps client-server communication by sending and retrieving responses, which also means it conforms to REST constraints. It is stateless and concedes separation between a client and server, or we may say it relies on the client-server protocol(mostly HTTP).
In REST architecture, clients and servers are independent because they are not concerned with each other’s internal parts. On the condition that the interface is the same, they can go through changes independently without affecting each other, which makes it flexible, scalable, and reliable.
If you’ve heard REST and RESTful in the same sentence and are wondering what the difference is, they are the same. A RESTful API follows a set of rules known as the Representational State Transfer (REST), which has been the standard for API development since the 2000s. In other words, REST is the set of rules, while RESTful refers to the API complying with the set of rules.
RESTful API organizes resources into a set of unique URI known as Uniques Resources Identifiers to separate the different types of requests on the server or tell the server what to do with the requests. It comprises four parts, often referred to as Anatomy. Here are some of the components of the REST anatomy:
Endpoint: The endpoint consists of the URI (Unique Resource Identifier), which tells us how and where to find resources on the server. For a client to access the resource, an Identifier is needed. Assuming we’re using an HTTP Protocol, the identifier of our resource would look like this; http://www.example.com/user/1 - In this identifier, we have the domain name, the user, and the ID.
Methods: If a client requests certain data to an endpoint via HTTP, the request follows specific methods or HTTP VERB. The HTTP VERB specifies the action that needs to be performed to access or communicate with the resource, and these methods include;
POST - A POST request means we want to create a new resource. When we fill out a form on the web by entering our name, password, DOB, etc. It also means we’re sending data to the server.
GET - GET means we want to read the data of an existing result. We make GET requests whenever we enter a URL in our web browser to retrieve data from a specified resource.
PUT - PUT means to update an existing resource.
DELETE - This means to delete or remove existing resources.
Headers: Headers provide information between the client and server. They are also used for authentication purposes.
Data: The data or body is used to send information to the server. It tells the server when you want to add, replace or delete data.
There are many HTTP verb methods. However, those mentioned above are frequently used.







