REST API Design Cheatsheet
Quick reference for REST API design: HTTP methods, status codes, endpoints, request/response patterns, and best practices.
| Feature | Description | Example | Category |
|---|---|---|---|
| GET | Retrieve resource(s) | GET /users GET /users/1 | HTTP Methods |
| POST | Create a new resource | POST /users Body: { "name": "John" } | HTTP Methods |
| PUT | Update/replace a resource | PUT /users/1 Body: { "name": "John" } | HTTP Methods |
| PATCH | Update a resource partially | PATCH /users/1 Body: { "name": "Jane" } | HTTP Methods |
| DELETE | Delete a resource | DELETE /users/1 | HTTP Methods |
| 200 OK | Request succeeded | Response: { "id": 1, "name": "John" } | Status Codes |
| 201 Created | Resource created successfully | Response: { "id": 5 } | Status Codes |
| 204 No Content | Success but no content returned | DELETE /users/1 → 204 | Status Codes |
| 400 Bad Request | Client sent invalid data | Response: { "error": "Invalid email" } | Status Codes |
| 401 Unauthorized | Authentication required | Response: { "error": "Unauthorized" } | Status Codes |
| 403 Forbidden | Client not allowed | Response: { "error": "Forbidden" } | Status Codes |
| 404 Not Found | Resource not found | Response: { "error": "User not found" } | Status Codes |
| 500 Internal Server Error | Server error | Response: { "error": "Something went wrong" } | Status Codes |
| /users | Collection endpoint | GET /users → List all users | Endpoints |
| /users/{id} | Single resource endpoint | GET /users/1 → Get user with id 1 | Endpoints |
| Nested endpoints | Relationship endpoints | GET /users/1/posts → Get posts of user 1 | Endpoints |
| JSON payload | Send data as JSON | POST /users { "name": "John" } | Request & Response |
| Query parameters | Filter, sort, paginate | GET /users?limit=10&sort=name | Request & Response |
| Pagination | Limit and offset results | GET /users?limit=10&offset=20 | Request & Response |
| Use nouns in URIs | Avoid verbs; represent resources | /users, /products | Best Practices |
| Stateless | Each request contains all necessary info | No session on server | Best Practices |
| Versioning | Support API version | /api/v1/users | Best Practices |
| Consistent responses | Standardize JSON response format | { "success": true, "data": {...}, "error": null } | Best Practices |
| Error handling | Return proper status codes & messages | 404 + { "error": "Not found" } | Best Practices |