REST API
- REST stands for Representational State Transfer.
- It is a standardized software architecture style used for API communication between a client and a server.
Benefits of REST APIs:
- Simplicity and Standardization:
- Data formatting and request structuring are standardized and widely adopted.
- Scalability and Statelessness:
- Easily modifiable as service complexity grows without tracking data states across client and server.
- High Performance:
- Supports caching, maintaining high performance even as complexity increases.
Main Building Blocks:
- Request:
- Actions (==CRUD==): Create (POST), Read (GET), Update (PUT), Delete (DELETE).
- Components: Operation (HTTP method), Endpoint, Parameters/Body, Headers.
- Response:
- Typically in JSON format.
REST API Example: ice cream shop inteacting with cloud database.
- Endpoint example: “icecream.com/api/flavors”
- “api” indicates the API portion.
- “flavors” refers to the resource being accessed or modified.
Real-world Examples:
- Get Flavors:
- Operation: GET
- Endpoint: “/api/flavors”
- Response: Array of flavor resources.
- Update Flavor:
- Operation: PUT
- Endpoint: “/api/flavors/1”
- Body: New flavor data.
- Response: Confirmation of update.
- Create New Flavor:
- Operation: POST
- Endpoint: “/api/flavors”
- Body: New flavor data.
- Response: Confirmation of creation.