REST Principles
-
REST architecture is a standard way to design web APIs that allow communication between clients and servers using HTTP.
It treats data as resources, each identified by a unique URL, and follows a stateless design.
CRUD operations are used to manage data in APIs.
These operations are implemented using HTTP methods like POST, GET, PUT, and DELETE.
🔹 REST Architecture
REST (Representational State Transfer) is an architectural style for designing networked applications. In REST architecture, the client and server communicate over HTTP using standard methods, and each request is independent.
REST architecture focuses on resources, which are identified using URLs. Each resource represents data such as users, products, or orders.
Core Characteristics of REST Architecture:
Client and server are independent of each other
Communication happens using HTTP
Each request contains all required information
Server does not store client state (stateless)
This separation allows frontend and backend to evolve independently.
Example:
A frontend application requests user data from a backend API:
GET /users
GET API Request and JSON Response
This example shows how a frontend application requests user data from a backend API using a GET /users request. The server responds with a JSON array containing user information, which the frontend can display or process further.
[
{ "id": 1, "name": "Amit" },
{ "id": 2, "name": "Neha" }
]
Include labels: “Stateless Request”, “Resource”, “JSON Response”.
🔹 CRUD Operations
CRUD stands for Create, Read, Update, Delete. These operations represent the basic actions performed on data in any application.
In REST APIs, CRUD operations are mapped to standard HTTP methods, making API behavior consistent and predictable.
CRUD Mapping with HTTP Methods:
Create → POST
Read → GET
Update → PUT
Delete → DELETE
Each operation works on a specific resource identified by a URL.
Example:
Creating a new user:
POST /users
Reading users:
GET /users
Updating a user:
PUT /users/3
Deleting a user:
DELETE /users/3
Include labels: “Create”, “Read”, “Update”, “Delete”.