What is REST API and how does it work
REST constraints, statelessness, client-server model, uniform interface, HTTP verbs, resource naming
What is REST API and how does it work
The Core Idea
REST (Representational State Transfer) is an architectural style, not a protocol. It defines six constraints that make distributed systems predictable and scalable. The most critical: statelessness. Every request must carry all the information needed to process it. The server stores no session state between requests.
HTTP Verbs Map to Actions
REST uses HTTP methods to express intent:
- GET โ read a resource, safe and idempotent
- POST โ create a new resource
- PUT โ replace a resource entirely
- PATCH โ partial update
- DELETE โ remove a resource
Idempotency matters: calling DELETE /users/42 ten times has the same effect as calling it once. POST is not idempotent โ each call may create a new resource.
Resource Naming Rules
Use nouns, not verbs. Collections are plural:
# Good
GET /articles
GET /articles/99
POST /articles
# Bad
GET /getArticles
GET /fetchArticleById?id=99Nest resources only one level deep. /users/5/orders is fine. /users/5/orders/3/items/7/reviews is a maintenance nightmare. Flat is better than deeply nested beyond two levels.
