Working with HTTP Status Codes

1. Using 200 OK

WhenMethodsBody
Successful request returning dataGET, PUT, PATCH, POST (action)Resource representation

2. Using 201 Created

WhenRequired HeaderBody
Resource successfully createdLocation: /resource/{id}Created resource representation

3. Using 202 Accepted

WhenBodyHeader
Async processing startedOperation status URLLocation: /operations/{id}

4. Using 204 No Content

WhenBody
DELETE success, PUT/PATCH no body to returnMust be empty

5. Using 206 Partial Content

WhenRequired Headers
Range request (file download resume, video streaming)Content-Range: bytes 0-499/1234

6. Using 304 Not Modified

WhenBodyTriggered By
Cached resource still validEmptyIf-None-Match matches ETag, or If-Modified-Since not exceeded

7. Using 400 Bad Request

CauseBody
Malformed JSON, missing required field, invalid syntaxError details with field-level errors

8. Using 401 Unauthorized

WhenRequired Header
Missing/invalid/expired credentialsWWW-Authenticate: Bearer realm="api"
Note: Misnamed historically — 401 means "unauthenticated". Use 403 for "authenticated but not allowed".

9. Using 403 Forbidden

WhenNote
Authenticated but lacks permission for resource/actionDo not reveal whether resource exists (use 404 for sensitive cases)

10. Using 404 Not Found

WhenAlternative
Resource does not existUse 410 Gone for permanently removed

11. Using 405 Method Not Allowed

WhenRequired Header
Resource exists, method not supportedAllow: GET, POST

12. Using 409 Conflict

WhenExamples
State conflict prevents actionDuplicate username, version mismatch (optimistic lock), business rule violation

13. Using 422 Unprocessable Entity

WhenDifference from 400
Syntactically valid but semantically invalid (failed validation)400 = bad syntax; 422 = bad semantics

14. Using 429 Too Many Requests

WhenRequired Headers
Rate limit exceededRetry-After: 60, X-RateLimit-Remaining: 0

15. Using 500 Internal Server Error

WhenBody
Unhandled server exceptionGeneric message + correlation/trace ID; never stack traces in production

Status Code Quick Reference

  • 1xx Informational: 100, 101, 102 — rarely returned by APIs
  • 2xx Success: 200, 201, 202, 204, 206
  • 3xx Redirection: 301, 302, 304, 307, 308
  • 4xx Client Error: 400, 401, 403, 404, 405, 409, 410, 415, 422, 429
  • 5xx Server Error: 500, 501, 502, 503, 504