REST API YT + IntervieBit Rest is the most common communication standard between computers over internet.
API: Application Programming Interface: a way for two computers talk to each other.
REST:
- json.md + http.md
- Representational State Transfer
- the common API standard used by most mobile and web applications to talk to servers is called REST API.
- An API that follows the REST standard is called a RESTful API.
- post is
not idempotent
because it creates a new resource every time it is called | Get, put, delete, head, options areidempotent
because they do not change the state of the server. | Link - core components of HTTP Request & Response 6. & 7.
- put-vs-post
- idempotent and safe HTTP methods | Safe methods are those that do not change any resources internally |
- payload size: not in get and delete, but in post and put. sending data in the body of the request.
- Not possible to maintain sessions in REST on the server-side. | REST is stateless, meaning that each request is independent and does not rely on any previous.
URI's 1. Uniform Resource Identifier: > ://// URI = URL + URN eg. https://example.com/api/v3/users eg. https://example.com/api/v3/products
/users ✅ | /getUsers ❌
Client -> Server
POST /Procucts HTTP/1.1
Accept: 'application/json'
___________________________ ------------>
{
"name": "Product 1",
"price": 100,
"quantity": 10
}
<------------
HTTP/1.1 201 Created
GET /Products/1 HTTP/1.1
Accept: 'application/json'
__________________________
- Rest API is stateless, meaning that each request is independent and does not rely on any previous request. so easylly scalable and reliable.
To well behave REST API:
- if ther is to much of data, use pagination.
/products?limit=25&offset=50
- versioning of api is very importent.
/api/v1/products
- if ther is to much of data, use pagination.
- some best practices: Link
Also explore
- GraphQL
- SOAP
- gRPC
- AJAX: AJAX - Asynchronous javascript and XML 🤯. | AJAX is used for dynamic updation of UI without the need to reload the page. |
⚠️ MUST LEARN - Web Socket: Real-time communication, communication is bi-directional.
- Use Pagination: limit the number of items returned in a single response.
- asynchroneous logging: log the request and response in a separate thread.
- Caching: cache the response of the API. use redis or memcached.
- Payload Compression: compress the response payload.