HTTP status codes are the standardized vocabulary through which REST APIs communicate the outcome of client requests. Returning accurate status codes—rather than masking errors with generic 200 OK or unhelpful 500 Server Error responses—is essential for API contracts and client error handling.
HTTP status codes are categorized into five distinct ranges:
| Code | Name | Meaning | Standard Scenario |
|---|---|---|---|
200 | OK | Request succeeded. | Standard GET, PATCH, or PUT response. |
201 | Created | Resource created. | Successful POST request; returns new resource. |
204 | No Content | Succeeded, no body. | Successful DELETE request. |
400 | Bad Request | Malformed syntax / validation failed. | Serializer validation failed (missing required field). |
401 | Unauthorized | Unauthenticated. | Missing or invalid token (Bearer token invalid). |
403 | Forbidden | Authenticated but unauthorized. | User logged in, but lacks permission to view resource. |
404 | Not Found | Resource does not exist. | Object with specified ID or slug not in database. |
405 | Method Not Allowed | Verb not supported. | Sending DELETE to read-only resource. |
409 | Conflict | State conflict. | Duplicate entry violating unique constraint. |
429 | Too Many Requests | Rate limit exceeded. | API throttling threshold breached. |
500 | Internal Server Error | Unhandled backend crash. | Uncaught Python exception in view code. |
502 | Bad Gateway | Upstream failure. | Nginx cannot connect to Gunicorn socket. |
503 | Service Unavailable | Temporary outage. | Maintenance mode or overloaded cluster. |
401 Unauthorized vs 403 Forbidden Rule401 Unauthorized: Really means Unauthenticated. The client has not provided valid credentials. Header WWW-Authenticate is often included.403 Forbidden: The server knows who the client is, but the authenticated user lacks permission to execute the action. Sending credentials again will not change the outcome.In enterprise REST architectures, never return plain text strings or ad-hoc error shapes. Standardize on RFC 7807 (Problem Details for HTTP APIs):
DRF provides named constants in rest_framework.status:
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| HTTP Methods Overview | Installing DRF |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.