HTTP status codes are standardized numerical codes that indicate the outcome of a client’s request to a server during an HTTP transaction. These codes convey information about the success or failure of the request and are grouped into different classes based on the first digit of the status code.

HTTP status codes are 3-digit codes that indicate the status of an HTTP request. They are part of the HTTP response sent by a web server to a client. Status codes provide information about what happened to a request and help clients understand how to interpret the response. While the common codes like 200 OK and 404 Not Found are well known, there are many lesser used status codes that provide additional insight into responses.

The codes are grouped into classes based on the first digit:

1xx Informational Responses (100–199):

These statuses indicate a provisional response. The request is still processing and the client should continue with the request or ignore it if already finished.

  • 100 Continue: Indicates that the client should continue the request or ignore the response if the request is already finished.
  • 101 Switching Protocols: Sent in response to an Upgrade request header from the client and indicates the protocol the server is switching to.
  • 102 Processing (WebDAV): Indicates that the server has received and is processing the request, but no response is available yet.
  • 103 Early Hints: Primarily used with the Link header, allowing preloading of resources while the server prepares a response or preconnects to an origin

2xx Successful Responses (200–299):

  • 200 OK: The request succeeded. The meaning of “success” depends on the HTTP method:
    • GET: The resource has been fetched and transmitted in the message body.
    • HEAD: The representation headers are included in the response without any message body.
    • PUT or POST: The resource describing the result of the action is transmitted in the message body.
    • TRACE: The message body contains the request message as received by the server.
  • 201 Created: The request succeeded, and a new resource was created as a result (typically sent after POST requests or some PUT requests).
  • 202 Accepted: The request has been received but not yet acted upon. It is noncommittal, intended for cases where another process or server handles the request or for batch processing.
  • 203 Non-Authoritative Information: The returned metadata is not exactly the same as available from the origin server but is collected from a local or third-party copy (used for mirrors or backups).
  • 204 No Content: No content to send for this request, but the headers may be useful. The user agent may update its cached headers for this resource with the new ones.
  • 205 Reset Content: Tells the user agent to reset the document that sent this request.
  • 206 Partial Content: Used when the Range header is sent from the client to request only part of a resource.
  • 207 Multi-Status (WebDAV): Conveys information about multiple resources, where multiple status codes might be appropriate1.

3xx Redirection:

  • These status codes indicate that further action is needed to complete the request. They typically involve redirection or resource location changes.
  • Some common 3xx codes include:
    • 301 Moved Permanently: The requested resource has been permanently moved to a new location. Clients should update their bookmarks or links.
    • 302 Found (or Temporary Redirect): Similar to 301, but the redirection might be temporary. Clients should continue using the original URL.
    • 307 Temporary Redirect: Indicates a temporary redirection. The client should use the same method for the redirected request.
  • These codes help manage resource changes and guide clients to the correct location.

4xx Client Errors:

  • These codes indicate that the client’s request contains errors or cannot be fulfilled due to issues on the client side.
  • Common 4xx codes include:
    • 400 Bad Request: The server cannot process the request due to malformed syntax.
    • 401 Unauthorized: Authentication is required, and the client must provide valid credentials.
    • 403 Forbidden: The client does not have permission to access the requested resource.
    • 404 Not Found: The requested resource does not exist on the server.
    • 405 Method Not Allowed: The HTTP method used is not supported for the requested resource.
    • 429 Too Many Requests: The client has exceeded its rate limit for requests.
  • These codes help diagnose client-side issues and guide users toward proper usage.

5xx Server Errors:

  • These codes indicate that the server failed to fulfill a valid request due to issues on the server side.
  • Common 5xx codes include:
    • 500 Internal Server Error: A generic error message indicating an issue on the server.
    • 502 Bad Gateway: The server, while acting as a gateway or proxy, received an invalid response from an upstream server.
    • 503 Service Unavailable: The server is temporarily unable to handle requests due to maintenance or overload.
    • 504 Gateway Timeout: The server, acting as a gateway, did not receive a timely response from an upstream server.
  • These codes help identify server-related problems and inform users that the issue lies beyond their control.

The first digit defines the class, while the later digits provide more specific detail. Understanding status codes can help clients handle responses programatically and allow developers to debug requests.

OverView

Understanding status codes can help debug connectivity issues and improve the user experience. For example, a 404 status could trigger the application to provide an error message or redirect to a different page. While 2xx and 3xx codes are more common, awareness of less popular status codes can help developers utilize them for clearer communication and better handling of error cases. Overall, HTTP status codes are a simple but important part of communication between clients and servers.

Leave a Reply

Your email address will not be published. Required fields are marked *