HTTP status codes are three-digit numbers sent by web servers to indicate the status of a requested resource or the outcome of the request.
They provide a way for the server to communicate with the client (typically a web browser) about the success, failure, or other status of the request.
Understanding HTTP status codes can be a game-changer when you’re debugging a web application or examining server behavior.
Here’s a quick breakdown, categorized by the first digit:
- 1xx (Informational): These codes indicate that the request was received, and the process is continuing.
- 2xx (Successful): The request was received, understood, and processed successfully.
- 3xx (Redirection): Further action is required to complete the request. Most of these status codes suggest that the client go to another URL.
- 4xx (Client Errors): The request was faulty or cannot be fulfilled by the server. This is usually because of an error on the client’s part.
- 5xx (Server Errors): The server failed to fulfill a valid request. This means there’s a problem on the server’s side.
- 100 Continue: The initial part of the request has been received, and the client can continue.
- 101 Switching Protocols: The server is switching protocols as requested by the client.
- 102 Processing: Request received and understood but processing not yet completed.
- 200 OK: All is good, the request was successful.
- 201 Created: New resource created, often used after a POST request.
- 202 Accepted: Request accepted, but not yet processed.
- 203 Non-Authoritative Information: Info is from a third-party server.
- 204 No Content: The request succeeded, but there’s no content to send back.
- 205 Reset Content: Similar to 204, but requires the requester to reset the document view.
- 206 Partial Content: The partial GET request was successful.
- 300 Multiple Choices: Multiple options for the resource.
- 301 Moved Permanently: The URL is obsolete and moved permanently to a new address.
- 302 Found: Temporarily moved to a new URL. This status code indicates that the URI for the desired resource has shifted on a temporary basis. It’s worth noting that the URI may undergo additional alterations later on. Hence, for subsequent requests, the client should continue using the current URI.
- 303 See Other: The server is telling the client to go to a different web address to find the resource they requested. They should use a GET request to retrieve it.
- 304 Not Modified: Resource has not been changed; used to save bandwidth.
- 305 Use Proxy: Must access through a proxy.
- 307 Temporary Redirect: Temporarily moved, but future requests should still use the original URL.
4xx: Client Errors
- 400 Bad Request: The server couldn’t understand the request.
- 401 Unauthorized: Authentication needed, or current authentication doesn’t suffice.
- 402 Payment Required: Self-explanatory, right?
- 403 Forbidden: The server understands, but it refuses to authorize the request.
- 404 Not Found: You know this one! Resource not found.
- 405 Method Not Allowed: Request method not supported by the URL.
- 406 Not Acceptable: Resource can’t match request headers.
- 407 Proxy Authentication Required: The client must authenticate with a proxy.
- 408 Request Timeout: The server timed out waiting for the request.
- 409 Conflict: Conflicting request states.
- 410 Gone: Resource was there but is now gone.
- 411 Length Required: Missing Content-Length header.
- 412 Precondition Failed: One or more conditions in the request header fields failed.
- 413 Payload Too Large: Request body too big.
- 414 URI Too Long: The URL is too long.
- 415 Unsupported Media Type: Requested format not supported.
- 416 Range Not Satisfiable: Cannot serve the requested byte range.
- 417 Expectation Failed: Can’t meet the requirements of the Expect request header.
5xx: Server Errors
- 500 Internal Server Error: Something’s wrong on the server’s end.
- 501 Not Implemented: The server doesn’t support the functionality.
- 502 Bad Gateway: One server got an invalid response from another.
- 503 Service Unavailable: The server is down or too busy to handle the request.
- 504 Gateway Timeout: One server did not get a timely response from another.
- 505 HTTP Version Not Supported: The server doesn’t support the HTTP protocol version used.
- 506 Variant Also Negotiates: Content negotiation for the request results in a circular reference.
- 507 Insufficient Storage: The server is unable to store the representation needed to complete the request.
- 508 Loop Detected: WebDAV request contains an infinite loop.
- 510 Not Extended: Further extensions are required to fulfill the request.
These codes can give you a ton of insight into what’s happening between clients and servers, so they’re pretty handy to know!