File size: 3,841 Bytes
a7d7463 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | # 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: <https://api.com/users?page=2>; rel="next",
<https://api.com/users?page=5>; 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
|