🔥 HTTP Methods & Status Codes Quick Reference

🎯 HTTP Methods: The Four Essential Actions
GET
📖 Retrieve / Read Data
Purpose: Fetch data without changing anything
Safe: ✅ Yes - Read-only operation
Has Body: ❌ No request body
Common Use: View profiles, list items, search
# Get a user's profile GET /api/users/123 # Search for products GET /api/products?category=electronics # List all models GET /api/models
POST
➕ Create New Resource
Purpose: Create something new
Safe: ❌ No - Creates new data
Has Body: ✅ Yes - Contains new data
Common Use: Register user, submit form, upload
# Create new user POST /api/users Body: {"name": "Alice", "email": "[email protected]"} # Train new ML model POST /api/models/train Body: {"type": "random_forest", "data": [...]}
PUT
✏️ Update / Replace Resource
Purpose: Update existing resource completely
Safe: ❌ No - Modifies data
Has Body: ✅ Yes - Updated data
Common Use: Edit profile, update settings
# Update user profile PUT /api/users/123 Body: {"name": "Alice Smith", "email": "[email protected]"} # Update ML model config PUT /api/models/456 Body: {"hyperparameters": {"n_estimators": 200}}
DELETE
🗑️ Remove Resource
Purpose: Delete a resource permanently
Safe: ❌ No - Removes data
Has Body: ❌ Usually no body
Common Use: Delete post, remove account, clear data
# Delete a post DELETE /api/posts/789 # Remove trained model DELETE /api/models/456 # Delete user account DELETE /api/users/123
Method Action Safe? Idempotent? Example URL
GET Read/Retrieve ✅ Yes ✅ Yes GET /api/users/123
POST Create ❌ No ❌ No POST /api/users
PUT Update/Replace ❌ No ✅ Yes PUT /api/users/123
DELETE Remove ❌ No ✅ Yes DELETE /api/users/123
💡 What is Idempotent?
Calling the same operation multiple times produces the same result. GET is always idempotent (reading twice doesn't change data). DELETE is idempotent (deleting twice has same effect as once). POST is NOT idempotent (creating twice makes two items).
🚦 HTTP Status Codes: Understanding Responses
✅ 2xx - Success

The request was successful and the server did what you asked.

200
OK
Standard success response. Request completed successfully.
Example: GET /users/123 returns user data
201
Created
Resource successfully created. Usually from POST requests.
Example: POST /users creates new user account
204
No Content
Success, but no data to return. Often used with DELETE.
Example: DELETE /posts/123 successfully deleted
⚠️ 4xx - Client Errors

The request has a problem - usually something wrong with what YOU sent.

400
Bad Request
Request is malformed or has invalid syntax.
Example: Sending invalid JSON format
401
Unauthorized
Authentication required but not provided or invalid.
Example: Accessing protected endpoint without login
403
Forbidden
Authenticated but don't have permission for this action.
Example: Regular user trying to delete admin content
404
Not Found
The requested resource doesn't exist.
Example: GET /users/999999 (user doesn't exist)
422
Unprocessable Entity
Request format is correct but data failed validation.
Example: Email field contains invalid email format
429
Too Many Requests
Rate limit exceeded. Too many requests in given time.
Example: Making 1000 API calls in 1 minute
🔥 5xx - Server Errors

The server encountered a problem - not your fault, something went wrong on the server side.

500
Internal Server Error
Generic server error. Something broke unexpectedly.
Example: Unhandled exception in server code
502
Bad Gateway
Server got invalid response from upstream server.
Example: API gateway can't reach backend service
503
Service Unavailable
Server temporarily unavailable (maintenance, overloaded).
Example: Server undergoing maintenance or crashed

💡 Quick Decision Guide

When to use GET: Whenever you're just looking at data. Think "read-only". Safe to call multiple times.
When to use POST: Creating something new. Each call creates a new thing (not idempotent).
When to use PUT: Updating something that already exists. Replace the whole resource.
When to use DELETE: Removing something permanently. Idempotent - deleting twice is same as once.
Return 200: Success with data in response body.
Return 201: Successfully created something new (POST requests).
Return 400: Client sent malformed request or bad syntax.
Return 404: The thing you're looking for doesn't exist.
Return 422: Request format is fine but data failed validation rules.
Return 500: Something broke on the server - log the error and investigate.