HTTP Methods & Status Codes

🔗 REST API Lesson 2 Beginner

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
MethodActionIdempotent?Has Body?Example
GETRead / retrieve a resourceYesNoGET /users
POSTCreate a new resourceNoYesPOST /users
PUTReplace a resource entirelyYesYesPUT /users/1
PATCHPartially update a resourceNoYesPATCH /users/1
DELETERemove a resourceYesNoDELETE /users/1
HEADGET without response bodyYesNoHEAD /users
OPTIONSList allowed methods (CORS preflight)YesNoOPTIONS /users
2 HTTP Status Code Groups
RangeCategoryCommon Codes
1xxInformational100 Continue, 101 Switching Protocols
2xxSuccess200 OK, 201 Created, 204 No Content
3xxRedirection301 Moved Permanently, 304 Not Modified
4xxClient Errors400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 409 Conflict, 422 Unprocessable, 429 Too Many Requests
5xxServer Errors500 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.