REST (Representational State Transfer) API is an API that follows REST principles that allows communication between clients and servers using standard HTTP methods. REST is an architectural style for designing APIs that allows different applications to communicate over a network.
- Uses a client-server architecture to separate the user interface from server-side processing.
- Treats data and functionality as resources that can be accessed through unique URLs.
- Uses standard HTTP operations such as GET, POST, PUT, PATCH, and DELETE to work with resources.
Note: REST is an architectural style, not a programming language, framework, or protocol. HTTP is commonly used to implement REST APIs, but REST and HTTP are not the same.

Why Use REST
REST is used for building APIs because it provides a simple, scalable, and standard way for applications to communicate over a network.
- Uses standard HTTP methods and lightweight data formats such as JSON for simple communication.
- Supports scalable communication by keeping requests stateless.
- Allows clients and servers to use different programming languages and technologies.
- Provides flexibility by allowing resources to be accessed and managed independently.
- Easily integrates web applications, mobile apps, third-party services, and other systems.
Key Principles
REST follows these architectural constraints to ensure APIs are scalable, flexible, and easy to maintain:
- Client-Server: Separates the client interface from server-side data and logic.
- Stateless: Each request contains all information needed to process it.
- Cacheable: Responses can be cached to improve performance.
- Uniform Interface: Uses consistent resource URLs and standard HTTP methods.
- Layered System: Allows intermediaries such as gateways, proxies, and security layers.
- Code on Demand: Optionally allows servers to send executable code to clients.
Architecture
REST architecture defines how clients, servers, and resources interact through a REST API. It follows a client-server model where the client sends requests, the server processes them, and the server returns the requested data or result.
A typical REST architecture consists of:
- Client: Sends requests to access or modify resources.
- REST API: Receives requests and maps them to the required resources or operations.
- Server: Processes requests and applies the required business logic.
- Database: Stores and retrieves application data.

Resources in REST
In REST, a resource is any data or entity that an API provides access to, such as users, products, or orders. Each resource is identified by a unique URI.
For Example :
/users
/users/101
/products
/products/501
- /users represent a collection of users
- /users/101 represents a specific user.
- Resources can be retrieved or modified using standard HTTP methods.
How REST APIs Work
REST APIs follow a request-response cycle in which the client communicates with the server through a REST API.

- The client sends an HTTP request to access or modify a resource, such as requesting a product using GET/product/101
- The API receives the request and identifies the required resource and operation.
- The server performs the required operation, such as retrieving data from or updating the database.
- The server returns the result to the client, usually in a format such as JSON, along with an appropriate HTTP status code.
Use Cases
REST APIs are widely used across various industries to simplify communication between systems. Some common applications include:
- Social Media: Integrating third-party platforms like Facebook, Twitter, and Instagram for features like login, sharing, and posting.
- E-Commerce: Managing products, processing payments, handling orders, and customer management.
- Geolocation Services: GPS tracking, real-time location updates, and location-based services like finding nearby places.
- Weather Forecasting: Fetching weather data from external sources to provide real-time weather updates and forecasts.
Limitations
- Each request must include all required information, which can increase request size.
- REST follows a request-response model, so it is less suitable for real-time communication.
- Clients may receive more or less data than needed in some cases.
- REST does not have strict rules like SOAP, so implementations can vary between APIs.
- API versioning and maintaining backward compatibility can become difficult as the API grows.