The nine standard HTTP methods define the action to perform on a resource.
Method
Purpose
Request Body
Idempotent
Safe
GET
Retrieve a resource or collection
No
Yes
Yes
POST
Create a new resource
Yes
No
No
PUT
Replace a resource entirely
Yes
Yes
No
PATCH
Partially update a resource
Yes
No*
No
DELETE
Remove a resource
Optional
Yes
No
HEAD
Same as GET but no response body
No
Yes
Yes
OPTIONS
Describe communication options
No
Yes
Yes
Idempotent means making the same request multiple times produces the same result. *PATCH can be idempotent depending on implementation.
When to use PUT vs PATCH
PUT replaces the entire resource. Every field must be included. If a field is omitted, it is set to null or its default.
PATCH updates only the specified fields. Fields not included in the request body remain unchanged.
# PUT - replaces the entire user resource
curl -X PUT https://api.example.com/users/42 \
-H "Content-Type: application/json" \
-d '{"name":"Jane","email":"[email protected]","role":"admin"}'
# PATCH - updates only the role field
curl -X PATCH https://api.example.com/users/42 \
-H "Content-Type: application/json" \
-d '{"role":"admin"}'
200OK. Request succeeded. Standard response for GET.201Created. Resource was created. Return in response to POST.204No Content. Success, but no body returned. Common for DELETE.
3xx Redirection
301Moved Permanently. Resource has a new permanent URL.302Found. Temporary redirect. Method may change to GET.304Not Modified. Cached version is still valid.
4xx Client Errors
400Bad Request. Malformed syntax or invalid parameters.401Unauthorized. Authentication required or credentials invalid.403Forbidden. Authenticated but not authorized for this resource.404Not Found. Resource does not exist.405Method Not Allowed. HTTP method not supported for this endpoint.409Conflict. Request conflicts with current state (e.g., duplicate).422Unprocessable Entity. Valid syntax but semantically incorrect.429Too Many Requests. Rate limit exceeded. Check Retry-After header.
5xx Server Errors
500Internal Server Error. Generic server failure.502Bad Gateway. Upstream server returned invalid response.503Service Unavailable. Server is overloaded or under maintenance.504Gateway Timeout. Upstream server did not respond in time.
Common HTTP Headers
Request Headers
Header
Purpose
Example
Content-Type
Format of the request body
application/json
Accept
Expected response format
application/json
Authorization
Authentication credentials
Bearer eyJhbG...
User-Agent
Client identifier
MyApp/1.0
Cache-Control
Caching directives
no-cache
If-None-Match
Conditional request (ETag)
"abc123"
X-Request-ID
Trace ID for debugging
uuid-value
Response Headers
Header
Purpose
Example
Content-Type
Format of response body
application/json; charset=utf-8
Location
URL of created resource
/users/42
ETag
Version identifier for caching
"abc123"
Retry-After
Seconds to wait after 429/503
60
X-RateLimit-Limit
Max requests per window
1000
X-RateLimit-Remaining
Requests left in window
847
Link
Pagination links
</users?page=2>; rel="next"
CORS Headers
Header
Purpose
Access-Control-Allow-Origin
Which origins can access the API
Access-Control-Allow-Methods
Allowed HTTP methods for CORS
Access-Control-Allow-Headers
Allowed request headers for CORS
Access-Control-Max-Age
How long preflight results can be cached (seconds)
{
"type": "https://api.example.com/errors/validation",
"title": "Validation Error",
"status": 422,
"detail": "The 'email' field must be a valid email address",
"instance": "/users/42"
}
Best practice: Always return consistent error formats. Include a machine-readable error code, a human-readable message, and enough detail for the client to fix the problem.
API Versioning
URL path versioning (most common)
GET https://api.example.com/v1/users
GET https://api.example.com/v2/users
# Resource collections
GET /users # List users
POST /users # Create user
GET /users/42 # Get user 42
PUT /users/42 # Replace user 42
PATCH /users/42 # Update user 42
DELETE /users/42 # Delete user 42# Sub-resources
GET /users/42/posts # List posts by user 42
POST /users/42/posts # Create post for user 42# Filtering, sorting, pagination
GET /users?role=admin&sort=-created_at&page=2&limit=25
Test Your APIs with ToolPipe
Use our webhook tester, JWT decoder, and JSON formatter to build and debug APIs faster.