Exploring REST API: A Tale
Demystifying REST APIs: The Building Blocks Explained
💠API = Application Programming Interface.
If you are hungry and order from a restaurant then the delivery boy delivers your food to you. The delivery boy here works as an API.
An API is a set of rules, agreements, or protocols that allows different software applications to communicate with each other.
💠REST = REpresentational State Transfer.
REST API is an architectural style that imposes constraints on APIs for creating web services to allow communication between clients and servers over HTTP protocol.
🔖In the context of REST we refer to data as resources.
Breaking down the word RESTful
💠REpresentational
When we are transferring resources doesn't mean the resources themselves are transferred! It transfers the representation of that particular resource, typically using standardized formats such as JSON (JavaScript Object Notation) or XML (eXtensible Markup Language).
🔖Representational emphasizes that resources are not accessed directly but rather through their representations.
💠State
Condition or situation of the resource at a specific point in time. In programming, we can think of it as the properties of an object.
💠ful in RESTful
The suffix ful in RESTful indicates that the API is full of or adheres to REST principles.
💠T for Transfer
🔖The API that transfers the representation of resource states between client and server by following some principles is called RESTful API.
REST Principles
💠Uniform Interface
All the API requests should behave identically every time it is being called, no matter how many times it is being called, and no matter from where it is being called. The REST API should ensure that the same piece of data belongs to only one uniform resource identifier (URI)
💠Client-Server Architecture
The client and server will be separated from each other (separation of concern). They will talk to each other through requests and responses.
💠Statelessness
Each request to the server will be sufficient enough that the server will respond based on the request, i.e. server will not rely on any stored information or state to process any request.
💠Cacheability
Server responses would be labeled as cacheable or non-cacheable. This allows clients to reuse responses, improving performance and scalability.
💠Layered System
The architecture may consist of multiple layers, each aware only of the layer beneath, which promotes scalability and enables intermediaries such as load balancers and caches.
💠Code on Demand (Optional)
Servers can provide executable code (for example JavaScript) to clients optionally, which can help extend client functionality.