■ RESTful APIs - Study Notes
A **RESTful API (Representational State Transfer API)** is an architectural style for designing
networked applications. It relies on stateless, client-server communication, often using HTTP
methods like GET, POST, PUT, DELETE for performing CRUD operations.
■ Key Principles of REST
1 Stateless: Each request contains all the information needed (no session stored).
2 Client-Server Separation: UI (frontend) is separated from data (backend).
3 Uniform Interface: Standard HTTP methods (GET, POST, PUT, DELETE).
4 Cacheable: Responses can be cached to improve performance.
5 Layered System: Client does not need to know if it is connected directly or via intermediaries.
6 Code on Demand (optional): Servers can send executable code (like JavaScript).
■■ Common HTTP Methods in RESTful APIs
1 GET → Retrieve resource data.
2 POST → Create new resource.
3 PUT → Update/replace an existing resource.
4 PATCH → Update/modify part of a resource.
5 DELETE → Remove a resource.
■ Advantages of RESTful APIs
1 Scalability due to statelessness.
2 Flexibility across platforms and languages.
3 Lightweight and efficient over HTTP.
4 Easy integration with frontend frameworks and mobile apps.
5 Widely adopted industry standard.
■ Example: REST API Endpoint
**GET /api/users/1** → Retrieves data of user with ID 1. **POST /api/users** → Creates a new
user. **PUT /api/users/1** → Updates details of user 1. **DELETE /api/users/1** → Deletes user 1.
■ Real-World Use Cases
1 Web applications (React, Angular, Vue apps fetching API data).
2 Mobile apps (iOS/Android apps communicating with backend).
3 Cloud services and microservices communication.
4 IoT devices exchanging data with servers.
■■■ Author: Generated by ChatGPT