HTTP Methods & Status Codes
HTTP methods (also called verbs) define the type of action to perform on a resource. HTTP status codes tell the client exactly what happened with their request. Choosing the right verb and status code is the foundation of a well-designed REST API.
1 The Core HTTP Methods
| Method | Action | Idempotent? | Has Body? | Example |
|---|---|---|---|---|
| GET | Read / retrieve a resource | Yes | No | GET /users |
| POST | Create a new resource | No | Yes | POST /users |
| PUT | Replace a resource entirely | Yes | Yes | PUT /users/1 |
| PATCH | Partially update a resource | No | Yes | PATCH /users/1 |
| DELETE | Remove a resource | Yes | No | DELETE /users/1 |
| HEAD | GET without response body | Yes | No | HEAD /users |
| OPTIONS | List allowed methods (CORS preflight) | Yes | No | OPTIONS /users |
2 HTTP Status Code Groups
| Range | Category | Common Codes |
|---|---|---|
| 1xx | Informational | 100 Continue, 101 Switching Protocols |
| 2xx | Success | 200 OK, 201 Created, 204 No Content |
| 3xx | Redirection | 301 Moved Permanently, 304 Not Modified |
| 4xx | Client Errors | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 409 Conflict, 422 Unprocessable, 429 Too Many Requests |
| 5xx | Server Errors | 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable |
3 Correct Method & Status Mapping
HTTP — REST Method Examples
# List all users
GET /api/users -> 200 OK (with array body)
# Create user
POST /api/users -> 201 Created (with new resource body)
# Get specific user
GET /api/users/42 -> 200 OK | 404 Not Found
# Full replace
PUT /api/users/42 -> 200 OK (with updated body)
# Partial update
PATCH /api/users/42 -> 200 OK (with updated body)
# Delete — returns NO body
DELETE /api/users/42 -> 204 No Content
# Bad request body
POST /api/users -> 400 Bad Request (missing required fields)
# No token
GET /api/admin -> 401 Unauthorized
# Valid token, wrong permissions
GET /api/admin -> 403 Forbidden
4 Code Challenge
Challenge: Using curl or Postman, test all 5 CRUD operations against
https://jsonplaceholder.typicode.com/posts and record the HTTP method, URL, request body (if any), and the response status code for each.