REST (Representational State Transfer)
- Represent data in JSON or XML
- SIX Architectural Constraints
- Uniform Interface
- Completely Stateless (does not remember about previous request)
- Native Caching
- It is supported by REST-api itself and there is no explicit need of configuration
- Client-Server Architecture
- Layered System
- Ability to provide Executable code to the client
- PROS
- GET, POST, PUT, DELETE. OPTIONS, PATCH HTTP Methods are used
- Client & Server are completely decoupled from one another
- flexible formats (?format=json && ?format=xml) which makes it better for public facing APIs
- CONS
- No binding contract on what structure is used for messages.
- Your API sends "100.00" as
string
, the third party user expects afloat
100 value
- Your API sends "100.00" as
- Over-fetching and Under-fetching causing multiple API requests or slowed down response
- You want only name, id for application but get the entire user data through the API
- You want name and app-id but you have to make two API calls for user and for app slowing down the process.
- No binding contract on what structure is used for messages.
Request Methods | Usage |
---|---|
GET | Retrieve Data (Read) |
POST | Send Data (Create) |
PUT | Usually Replaces entire resource |
PATCH | Used for partial Delete |
DELETE | Deletes Data (Delete) |
Code range | Meaning | Example |
---|---|---|
2xx |
Success | 200 - OK 201 - Created 204 - No content (silent OK) |
3xx |
Redirection | 301 - Moved (path changed) |
4xx |
Client error | 400 - Bad request 401 - Unauthorized 403 - Not Permitted 404 - Not Found |
5xx |
Server error | 500 - Internal server error 502 - Bad gateway 504 - Gateway timeout |