REST API¶
REST API is a set of rules standardized to make API.
Basics¶
- REST: REpresentational State Transfer
- RESTful: API that uses REST to communicate.
- It is a standardized software architecture type to communicate in the industry.
Why they are used?¶
- Simple and Standardized: No worry about formatting. Data is Standardized as JSON.
- Scalable: Easy to grow as application grows.
- Client-Server architecture: Offloads computation to a server rather than on client side.
- Stateless: Does not Store Data on the Client side during request or response.
- Layered System & Cacheibility: The system can save pre calculated results for systems that don't change.
Operations¶
HTTP API work on the CRUD Base. REST Equivalent are:
- C: Create -> POST : Add New Data to the Server
- R: Read -> GET : Fetch Data from the server
- U: Update -> PUT : Complete Replacement of resource in server
- D: Delete -> DELETE : Delete Data from the Server
- PATCH : Practical Update a resource in Server
Structure of REST¶
sequenceDiagram
participant Client
participant Server
Client->>Server: Request
loop GetData
Server->>Server: Collect Data from System
end
Server-->>Client: Response
Request Structure¶
Sent generally as an HTTP Request in format: http://<domain>/API/Endpoint
classDiagram
Request : Header (API Key or Authentication Data)
Request : Operation (Post/Get/Put/Delete)
Request : EndPoint (Task Request)
Request : Parameters/Body (Input Parameters for Request generally in form of json)
Response¶
Response generally are HTTP Codes which indicate different responses:
- 2xx: Success
- 4xx: Something wrong with request
- 5xx: Something wrong with server
classDiagram
Response : Status Code
Response : JSON Response