Understanding REST APIs 🚀
Let's get started with the Full Forms first
REST stands for Representational State Transfer
API stands for Application Programming Interface
What are REST APIs?
REST APIs are an interface between 2 systems that want to share data.
REST is a standard and can be implemented over different protocols, In most cases, it is implemented via the
HTTP protocol, it provides different methods like
POST which makes it easier.
Typically, we want to transfer data from 1 layer of the system to another layer of the system.
client -> server or
server -> server
Let’s take the example of Restaurants data.
All the restaurant data sits inside a database, so this data is a resource. We want to share this data with the client. The representation of this data which is on the server will be different from the client representation. Meaning there can be multiple representations of the same data.
The most common way to transfer data in REST is via
JSON and any REST API implemented over HTTP protocol will be composed of URI
What is URI?
URI stands for
Uniform Resource Identifier , It is a technical term used for the names of all resources Connected to the World Wide Web. URIs established protocols over the internet to conduct the connection between resources.
URI looks something like this:
2 Important Terms:
PATHparameter: Variable in URI path that helps in pointing towards specific resource
Here, 1 is a variable here which points to restaurant 1s total orders
QUERYparameter: Variable in URI path that helps in querying/ filtering through a list of resources
Here, search is the query param key, and a sub is a value.
HTTP Request methods
HTTP request methods are a set of methods to indicate the desired action to be performed for a given resource.
Few of the HTTP Request methods:
GET: read information about resource
POST: create a new resource
PUT: update the resource (if exists, else creates new)
PATCH: update the resource
DELETE: delete the resources.
These are the main HTTP methods used. (There are other methods as well for different use cases)
GET the method only fetches the resources, methods like
Post can modify a particular resource or create a new resource.
So, with these methods, we send data back with the request in the form of request payloads and we get an acknowledgment from the server which we call the response body.
HTTP Status Codes
With every REST API implemented over
HTTP, we get something called
Response codes/ HTTP status codes, these are important because they inform the client about the type of response received.
So there are response codes like:
4xx: Problem with the client
5xx: Problem with the server
Another important part of
HTTP is HTTP headers.
They are the set of attributes that stores the
metadata associated with the API.
For example, if we want to send and accept responses in English, then we set
There are headers related to cache and authorization. Remember that headers are not related to resource data.
So, these are a few concepts that we have to keep in mind w.r.t REST APIs.
Hope you learned something new today.