# HTTP Status Codes ## Success Codes (2xx) | Code | Name | Description | |------|------|-------------| | 200 | OK | Standard success response | | 201 | Created | Resource successfully created | | 202 | Accepted | Request accepted for processing | | 204 | No Content | Success with no body | | 206 | Partial Content | Returning partial data | ## Redirection Codes (3xx) | Code | Name | Description | |------|------|-------------| | 301 | Moved Permanently | Resource moved permanently | | 302 | Found | Temporary redirect | | 303 | See Other | Redirect to different URL | | 304 | Not Modified | Use cached version | | 307 | Temporary Redirect | Temporary redirect | | 308 | Permanent Redirect | Permanent redirect | ## Client Error Codes (4xx) | Code | Name | Description | |------|------|-------------| | 400 | Bad Request | Invalid request syntax | | 401 | Unauthorized | Authentication required | | 402 | Payment Required | Reserved for future use | | 403 | Forbidden | Authenticated but not permitted | | 404 | Not Found | Resource doesn't exist | | 405 | Method Not Allowed | HTTP method not supported | | 406 | Not Acceptable | Cannot produce acceptable response | | 408 | Request Timeout | Client took too long | | 409 | Conflict | Request conflicts with state | | 410 | Gone | Resource permanently removed | | 413 | Payload Too Large | Request body exceeds limit | | 414 | URI Too Long | URL exceeds max length | | 415 | Unsupported Media Type | Invalid content type | | 422 | Unprocessable Entity | Validation failed | | 429 | Too Many Requests | Rate limit exceeded | ## Server Error Codes (5xx) | Code | Name | Description | |------|------|-------------| | 500 | Internal Server Error | Generic server error | | 501 | Not Implemented | Feature not implemented | | 502 | Bad Gateway | Invalid response from gateway | | 503 | Service Unavailable | Server temporarily down | | 504 | Gateway Timeout | Gateway timeout | | 507 | Insufficient Storage | Storage limit reached | | 511 | Network Authentication | Requires auth on network | ## Common Use Cases ### 200 OK ```json // Standard response { "data": {...} } ``` ### 201 Created ```json // With created resource { "data": { "id": 123, "name": "New Item" } } // Headers: Location: /resources/123 ``` ### 400 Bad Request ```json { "error": { "code": "VALIDATION_ERROR", "message": "Invalid input", "details": [...] } } ``` ### 401 Unauthorized ```json { "error": { "code": "AUTH_REQUIRED", "message": "Please login to continue" } } ``` ### 403 Forbidden ```json { "error": { "code": "PERMISSION_DENIED", "message": "You don't have access to this resource" } } ``` ### 404 Not Found ```json { "error": { "code": "NOT_FOUND", "message": "Resource not found" } } ``` ### 429 Too Many Requests ```json { "error": { "code": "RATE_LIMITED", "message": "Too many requests", "retryAfter": 60 } } // Headers: Retry-After: 60 ``` ### 500 Internal Server Error ```json { "error": { "code": "INTERNAL_ERROR", "message": "Something went wrong" } } ``` ## Response Headers ### Standard Headers ``` Content-Type: application/json Content-Length: 1234 Connection: keep-alive Cache-Control: max-age=3600 ``` ### Rate Limiting Headers ``` X-RateLimit-Limit: 100 X-RateLimit-Remaining: 95 X-RateLimit-Reset: 1640000000 ``` ### Pagination Headers ``` Link: ; rel="next", ; rel="last" ``` ## Security Best Practices 1. Never reveal internal error details in production 2. Use generic error messages for 500 errors 3. Log detailed errors server-side 4. Return appropriate status codes 5. Include error codes for client handling