Skip to content

HTTP Cheat Sheet

CodeMeaningWhen to Use
200OKRequest succeeded, body has data
201CreatedResource created (POST)
204No ContentSuccess, no body (DELETE, PUT)
CodeMeaningWhen to Use
301Moved PermanentlyURL changed forever
302FoundTemporary redirect
304Not ModifiedClient cache still valid
CodeMeaningWhen to Use
400Bad RequestMalformed syntax, invalid data
401UnauthorizedMissing or invalid credentials
403ForbiddenValid credentials, no permission
404Not FoundResource doesn’t exist
409ConflictState conflict (duplicate, etc.)
422Unprocessable EntityValid syntax, semantic errors
429Too Many RequestsRate limited
CodeMeaningWhen to Use
500Internal Server ErrorUnexpected server failure
502Bad GatewayUpstream server failed
503Service UnavailableServer overloaded/down
504Gateway TimeoutUpstream server timeout
Terminal window
# GET request
curl https://api.example.com/users
# With headers
curl -H "Authorization: Bearer TOKEN" https://api.example.com/users
# POST JSON
curl -X POST \
-H "Content-Type: application/json" \
-d '{"name": "alice"}' \
https://api.example.com/users
# POST form data
curl -X POST \
-d "name=alice&email=alice@example.com" \
https://api.example.com/users
# Upload file
curl -X POST \
-F "file=@document.pdf" \
https://api.example.com/upload
FlagPurpose
-X METHODHTTP method (GET, POST, PUT, DELETE)
-H "K: V"Add header
-d "data"Request body
-F "k=v"Form field (multipart)
-o fileWrite output to file
-OSave with remote filename
-LFollow redirects
-iInclude response headers
-IHEAD request (headers only)
-vVerbose (debug)
-sSilent (no progress)
-kSkip TLS verification
-u user:pwdBasic auth
Terminal window
# Pretty print JSON response
curl -s https://api.example.com/users | jq
# Extract field
curl -s https://api.example.com/users | jq '.[0].name'
# Filter and format
curl -s https://api.example.com/users | jq '.[] | {name, email}'
# Check status code
curl -s -o /dev/null -w "%{http_code}" https://api.example.com/health
HeaderPurposeExample
AuthorizationCredentialsBearer eyJhbGc...
Content-TypeBody formatapplication/json
AcceptDesired response formatapplication/json
User-AgentClient identifierMyApp/1.0
Cache-ControlCaching directivesno-cache
If-None-MatchConditional (ETag)"abc123"
If-Modified-SinceConditional (date)Wed, 21 Oct 2024 07:28:00 GMT
HeaderPurposeExample
Content-TypeBody formatapplication/json; charset=utf-8
Cache-ControlCaching instructionsmax-age=3600
ETagResource version"abc123"
LocationRedirect target / created URL/users/42
X-RateLimit-*Rate limit infoX-RateLimit-Remaining: 99
ActionMethodPathSuccess Code
List allGET/resources200
Get oneGET/resources/:id200
CreatePOST/resources201
Full updatePUT/resources/:id200
Partial updatePATCH/resources/:id200
DeleteDELETE/resources/:id204
GET /users?page=2&limit=20 # Pagination
GET /users?sort=name&order=desc # Sorting
GET /users?filter[role]=admin # Filtering
GET /users?fields=id,name,email # Sparse fields
GET /users?include=posts,comments # Related resources
Terminal window
curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..." \
https://api.example.com/users
Terminal window
# With -u flag
curl -u username:password https://api.example.com/users
# Manual header
curl -H "Authorization: Basic $(echo -n user:pass | base64)" \
https://api.example.com/users
Terminal window
# In header
curl -H "X-API-Key: abc123" https://api.example.com/users
# In query string (less secure)
curl "https://api.example.com/users?api_key=abc123"
Terminal window
# See full request/response
curl -v https://api.example.com/users
# Time breakdown
curl -w "
DNS: %{time_namelookup}s
Connect: %{time_connect}s
TTFB: %{time_starttransfer}s
Total: %{time_total}s
" \
-o /dev/null -s https://api.example.com/users
# Test endpoint availability
curl -s -o /dev/null -w "%{http_code}" https://api.example.com/health