Introduction
Web development and working with APIs are closely related to understanding and using HTTP status codes. These codes report the result of an HTTP request, whether it's a successful execution, a redirection, or an error. Knowing their meaning and proper use plays an important role in ensuring effective interaction between the client and the server.
What are HTTP status codes?
HTTP status codes — are three-digit numbers returned by the server in response to an HTTP request from the client. They are divided into five categories, each with its own meaning and application.
Categories of HTTP status codes
Informational responses (100–199)
Informational status codes indicate that the request was accepted and processing is continuing.
- 100 Continue: The server received the initial request headers and the client should continue sending the request body.
- 101 Switching Protocols: The client requested a protocol change, and the server confirmed that it will do so.
- 102 Processing: The server received the request, but processing is not yet complete.
Successful responses (200–299)
These status codes indicate that the request was executed successfully.
- 200 OK: The request was executed successfully. The response depends on the request method (e.g., the data requested resource for GET).
- 201 Created: The request resulted in the creation of a new resource. A link to the created resource is usually transmitted in the
Locationheader. - 202 Accepted: The request was accepted, but not yet processed. This does not guarantee that the request will be executed.
- 203 Non-Authoritative Information: The server returned meta-information that differs from what is stored on the server.
- 204 No Content: The request was executed successfully, but the response body is empty.
- 205 Reset Content: The request was executed successfully, and the client should reset the document representation.
- 206 Partial Content: The server returns only a part of the resource, as requested by the client (used for resuming interrupted downloads).
Redirections (300–399)
Redirects indicate that the client must perform additional actions to complete the request.
- 300 Multiple Choices: The request has multiple possible answers. The user or client must choose one of them.
- 301 Moved Permanently: The requested resource has been moved to a new permanent URL.
- 302 Found: The requested resource is temporarily located at a different URL.
- 303 See Other: The client should use a different URL to access the resource, for example, for a POST request.
- 304 Not Modified: The requested resource has not changed since the last request. The client can use the cached version.
- 307 Temporary Redirect: Temporary redirect to another URL. The request method should not be changed.
- 308 Permanent Redirect: Permanent redirect to a new URL. The request method should not be changed.
Client Errors (400–499)
These status codes indicate errors that occurred due to client-side issues.
- 400 Bad Request: The server does not understand the request due to incorrect syntax.
- 401 Unauthorized: Authentication is not performed or not provided.
- 403 Forbidden: The server understood the request but refuses to execute it.
- 404 Not Found: The server cannot find the requested resource.
- 405 Method Not Allowed: The method specified in the request is not allowed for the resource.
- 406 Not Acceptable: The requested resource does not match the criteria specified in the
Acceptheader of the request. - 407 Proxy Authentication Required: The client must authenticate through a proxy.
- 408 Request Timeout: The server has been waiting for a request from the client for too long.
- 409 Conflict: The request cannot be completed due to a conflict with the current state of the resource.
- 410 Gone: The requested resource is no longer available and has no new address.
- 411 Length Required: The request must contain a
Content-Lengthheader.
Expect header of the request could not be fulfilled by the server.Server Errors (500–599)
These status codes indicate problems that occurred on the server side.
- 500 Internal Server Error: The server encountered an unexpected error and cannot fulfill the request.
- 501 Not Implemented: The request method is not supported by the server.
- 502 Bad Gateway: The server received an invalid response from an upstream server.
- 503 Service Unavailable: The server is temporarily unavailable due to overload or scheduled maintenance.
- 504 Gateway Timeout: The server did not receive a timely response from an upstream server.
- 505 HTTP Version Not Supported: The server does not support the HTTP protocol version used in the request.
Frequently Asked Questions
What are HTTP status codes?
HTTP status codes are three-digit numbers returned by the server in response to an HTTP request from the client. They are divided into five main categories, each with its own meaning and application.
Why are HTTP status codes needed?
HTTP status codes help the client (e.g., a web browser) and the server communicate effectively. They inform the client about the result of the request: whether the request was successful, whether a redirect is required, or whether an error occurred.
What does status code 200 mean?
Status code 200 OK means that the request was successfully executed and the server returned the requested data.
What is the difference between status code 301 and 302?
Status code 301 Moved Permanently means that the resource has been moved to a new permanent URL, while 302 Found indicates a temporary movement of the resource.
What should I do if I get status code 404?
Status code 404 Not Found means that the server cannot find the requested resource. Make sure that the URL is entered correctly and that the resource exists on the server.
How to fix the error 500 Internal Server Error?
Error 500 Internal Server Error indicates a problem on the server. Check the server logs for more information about the cause of the error and fix it.
What does status code 503 Service Unavailable mean?
Status code 503 Service Unavailable means that the server is temporarily unable to handle the request. This may be caused by server overload or scheduled maintenance.
How to distinguish between a client error and a server error?
Client errors have status codes in the range 400–499, while server errors are in the range 500–599. Client errors are usually caused by an incorrect request from the client, while server errors indicate problems on the server side.