REST API
Hassan Juma
Solution Architect | DevOps Engineer | CKA | CKAD | Kubernetes | SRE | Platform Engineering
REST API is a software architectural style for Backend.
REST = “REpresentational State Transfer”.?API = Application Programming Interface
Its purpose is to induce performance, scalability, simplicity, modifiability, visibility, portability, and reliability.
REST API is?Resource-based, a resource is an object and can be access by a URI. An object is “displayed”/transferred via a?representation?(typically JSON). HTTP methods will be actions on a resource.
Example:
There are 6 constraints:
1. Uniform Interface
HTTP verbs
URIs - resource name
A resource representation is accessible by a URI:
HTTP Response
In the HTTP Response, the client should verify the information of two things:
Some important status code:
领英推荐
2. Stateless
The server is independent of the client. The server doesn’t store user client information/state. Each request contains enough context to process it (HTTP Headers, etc.)
Some authentication systems like OAuth have to store information on the server side but they do it with REST API design.
3. Cacheable
All server responses (resource representation) are cacheable:
Caches are here to improve performances. In a REST API, clients don’t care about the caching strategy, if the resource representation comes from a cache or from a database…
4. Client-Server
REST API is designed to separate Client from the Server. The server doesn’t know who is talking to it. Clients are not concerned with data storage => the portability of client code is improved. Servers are not concerned with the user interface or user state so that servers can be simpler and more scalable
5. Layered System
Client can’t assume direct connection to server. Intermediary servers may improve system scalability by enabling load-balancing and by providing shared caches. Layers may also enforce security policies.
6. Code on Demand (optional)
Server can temporarily: