HTTP Status Codes
HTTP status codes are standardized messages sent by web servers in response to client requests. They provide crucial information about the outcome of HTTP requests, helping developers and users understand what happened during the communication between the client and server.
From informational responses to success indicators, redirections, client errors, and server issues, these codes form the backbone of web communication.
1xx - Informational
100
Continue
The server has received the request headers and the client should proceed to send the request body.
Example Scenario
When uploading a large file, the client might send a request with the "Expect: 100-continue" header. The server responds with a 100 Continue status, signaling that the client should proceed with sending the file data.
Request
POST /upload HTTP/1.1
Host: example.com
Content-Length: 5000000
Expect: 100-continueResponse
HTTP/1.1 100 Continue
(followed by the actual file upload)2xx - Success
200
OK
The request was successful. The meaning of success varies depending on the HTTP method.
Example Scenario
A client requests a web page, and the server successfully returns the content.
Request
GET /index.html HTTP/1.1
Host: www.example.comResponse
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 12343xx - Redirection
301
Moved Permanently
The requested resource has been permanently moved to a new URL.
Example Scenario
A website has changed its domain from https://old-domain.com to https://new-domain.com.
Request
GET /page.html HTTP/1.1
Host: old-domain.comResponse
HTTP/1.1 301 Moved Permanently
Location: https://new-domain.com/page.html302
Found
The requested resource has been temporarily moved to a different URL.
Example Scenario
An e-commerce site temporarily redirects users from a product page to a special sale page.
Request
GET /product/123 HTTP/1.1
Host: www.example-shop.comResponse
HTTP/1.1 302 Found
Location: https://www.example-shop.com/sale/summer-special307
Temporary Redirect
The requested resource has been temporarily moved to another URL, and the original HTTP method should be used for the redirected request.
Example Scenario
A web service temporarily redirects POST requests to a backup server during maintenance.
Request
POST /api/data HTTP/1.1
Host: api.example.com
Content-Type: application/json
{"key": "value"}Response
HTTP/1.1 307 Temporary Redirect
Location: https://backup-api.example.com/api/data4xx - Client Errors
400
Bad Request
The server cannot or will not process the request due to an apparent client error.
Example Scenario
A client sends a malformed JSON payload in an API request.
Request
POST /api/users HTTP/1.1
Host: api.example.com
Content-Type: application/json
{
"name": "John Doe",
"email": "johndoe@example.com",
"age": "thirty"
}Response
HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Length: 85
{
"error": "Bad Request",
"message": "Age must be a number"
}403
Forbidden
The server understood the request but refuses to authorize it.
Example Scenario
A user tries to access an admin panel without proper permissions.
Request
GET /admin/dashboard HTTP/1.1
Host: www.example.com
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...Response
HTTP/1.1 403 Forbidden
Content-Type: text/html
Content-Length: 1234
<html>
<body>
<h1>403 Forbidden</h1>
<p>You do not have permission to access this resource.</p>
</body>
</html>404
Not Found
The requested resource could not be found on the server.
Example Scenario
A user tries to access a page that doesn't exist on the website.
Request
GET /non-existent-page.html HTTP/1.1
Host: www.example.comResponse
HTTP/1.1 404 Not Found
Content-Type: text/html
Content-Length: 12345xx - Server Errors
500
Internal Server Error
A generic error message when an unexpected condition was encountered on the server.
Example Scenario
A server-side script encounters an unhandled exception while processing a request.
Request
GET /process-data.php HTTP/1.1
Host: www.example.comResponse
HTTP/1.1 500 Internal Server Error
Content-Type: text/html
Content-Length: 1234502
Bad Gateway
The server, while acting as a gateway or proxy, received an invalid response from an upstream server.
Example Scenario
A load balancer is unable to get a valid response from one of the backend application servers.
Request
GET /api/user-data HTTP/1.1
Host: api.example.comResponse
HTTP/1.1 502 Bad Gateway
Content-Type: text/html
Content-Length: 1234
<html>
<body>
<h1>502 Bad Gateway</h1>
<p>The server encountered a temporary error and could not complete your request.</p>
</body>
</html>503
Service Unavailable
The server is currently unable to handle the request due to temporary overloading or maintenance of the server.
Example Scenario
An e-commerce website is temporarily down for maintenance during a planned upgrade.
Request
GET /shop HTTP/1.1
Host: www.example-shop.comResponse
HTTP/1.1 503 Service Unavailable
Content-Type: text/html
Content-Length: 1234
Retry-After: 3600
<html>
<body>
<h1>503 Service Unavailable</h1>
<p>Our site is currently undergoing scheduled maintenance. Please try again in one hour.</p>
</body>
</html>