Here's a list of common HTTP error codes (also called status codes) you might encounter
when building a Django API, along with a brief explanation of what each means:
1xx - Informational responses
These codes indicate that the server has received the request and is continuing to process it.
100 Continue: The server has received the request headers, and the client should proceed
to send the body of the request.
101 Switching Protocols: The server is switching protocols according to the client's
request.
2xx - Success
These codes indicate that the request was successfully received, understood, and accepted.
200 OK: The request was successful, and the server has returned the requested data (or
confirmed that the action was completed).
201 Created: The request was successful, and a new resource was created.
202 Accepted: The request has been accepted for processing, but the processing is not
complete.
204 No Content: The server successfully processed the request, but there's no content to
return (e.g., a successful DELETE request).
3xx - Redirection
These codes indicate that further action is required to complete the request.
301 Moved Permanently: The requested resource has been permanently moved to a new
URL.
302 Found: The resource has temporarily moved to a different URL.
304 Not Modified: The resource has not been modified since the last request (used for
caching).
4xx - Client Errors
These codes indicate that the client seems to have made an error in their request.
400 Bad Request: The server could not understand the request due to malformed syntax.
This usually happens when a required parameter is missing or invalid in the request.
401 Unauthorized: The request requires user authentication. This typically happens if an
API key, token, or other authentication credentials are missing or incorrect.
403 Forbidden: The server understood the request, but it refuses to authorize it. You
might be trying to access a resource you don't have permission to view.
404 Not Found: The requested resource could not be found on the server. This is
common when an endpoint is incorrect or the resource doesn't exist.
405 Method Not Allowed: The method used in the request (GET, POST, DELETE, etc.)
is not allowed for the specified resource.
406 Not Acceptable: The server cannot produce a response that meets the criteria given
in the request's Accept header.
407 Proxy Authentication Required: The client must authenticate with the proxy server
before the request can be fulfilled.
408 Request Timeout: The client did not produce a request within the time the server
was prepared to wait.
409 Conflict: The request could not be processed because of a conflict (e.g., duplicate
data).
410 Gone: The resource is no longer available and will not be available again.
411 Length Required: The server requires the Content-Length header to be specified
in the request.
412 Precondition Failed: A condition in the request headers was not met.
413 Payload Too Large: The request is too large for the server to process.
414 URI Too Long: The URI provided in the request is too long for the server to
process.
415 Unsupported Media Type: The media type of the request is not supported by the
server.
416 Range Not Satisfiable: The range specified in the request's Range header is invalid.
417 Expectation Failed: The server cannot meet the expectation indicated by the Expect
header.
422 Unprocessable Entity: The request was well-formed, but the server cannot process
the contained instructions (e.g., validation errors in form data).
429 Too Many Requests: The user has sent too many requests in a given amount of
time.
5xx - Server Errors
These codes indicate that the server failed to fulfill a valid request.
500 Internal Server Error: A generic error message indicating that the server
encountered an unexpected condition that prevented it from fulfilling the request.
501 Not Implemented: The server does not support the functionality required to fulfill
the request.
502 Bad Gateway: The server, while acting as a gateway or proxy, received an invalid
response from the upstream server.
503 Service Unavailable: The server is currently unable to handle the request due to a
temporary overload or scheduled maintenance.
504 Gateway Timeout: The server, while acting as a gateway or proxy, did not receive a
timely response from the upstream server.
505 HTTP Version Not Supported: The server does not support the HTTP protocol
version that was used in the request.
Django-specific Error Codes
When you're working with Django, especially with Django REST Framework (DRF), you might
see custom error codes:
422 Unprocessable Entity: Often used to indicate that a request was syntactically
correct, but the data validation failed. This is common in DRF's serializer validation.
400 Bad Request: In DRF, you might encounter this when serializer validation fails or
when the data sent is incomplete.
401 Unauthorized: Common if you're working with authentication mechanisms like
JWT or OAuth.
403 Forbidden: Often appears if a user doesn't have the proper permissions or roles to
access a resource.
404 Not Found: Usually when a URL pattern or a resource is not available.
405 Method Not Allowed: If you try to use a GET method on a view that only allows
POST requests, for example.