REST Understanding RESTful API design principles.
REST (Representational State Transfer) is an architectural style for designing networked applications. RESTful APIs use HTTP methods to perform CRUD operations on resources.
Principle Description Stateless Each request contains all info needed Client-Server Separation of concerns Cacheable Responses can be cached Uniform Interface Consistent resource-based URLs Layered System Client doesn't know if talking to server or intermediary
Good (resource-based):
GET /users # List users
GET /users/123 # Get user 123
POST /users # Create user
PUT /users/123 # Update user 123
DELETE /users/123 # Delete user 123
Bad (action-based):
GET /getUser?id=123
POST /createUser
POST /deleteUser
Operation Method Example Create POST POST /usersRead GET GET /users/123Update (full) PUT PUT /users/123Update (partial) PATCH PATCH /users/123Delete DELETE DELETE /users/123
POST /api/users HTTP / 1.1
Host : api.example.com
Content-Type : application/json
{
"name" : "John" ,
"email" : "john@example.com"
}
HTTP / 1.1 201 Created
Content-Type : application/json
Location : /api/users/123
{
"id" : 123 ,
"name" : "John" ,
"email" : "john@example.com"
}
Practice Example Use nouns, not verbs /users not /getUsersUse plural nouns /users not /userNest for relationships /users/123/ordersUse query params for filtering /users?role=adminVersion your API /v1/users or header
GET /users?page=2&limit=20
Response :
{
"data" : [ ... ],
"pagination" : {
"page" : 2 ,
"limit" : 20 ,
"total" : 100 ,
"next" : "/users?page=3&limit=20"
}
}
Explain REST principles (stateless, uniform interface)
Design resource-based URLs properly
Know when to use each HTTP method
Discuss pagination, filtering, versioning
Compare with GraphQL and gRPC