0% found this document useful (0 votes)
10 views4 pages

HTTP Status Codes Explained

The document outlines various HTTP error codes categorized into 2xx (Success), 4xx (Client Errors), and 5xx (Server Errors). Each category includes specific codes with descriptions and examples of their usage. The summary highlights the meaning of each code and the circumstances under which they are returned by the server.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

HTTP Status Codes Explained

The document outlines various HTTP error codes categorized into 2xx (Success), 4xx (Client Errors), and 5xx (Server Errors). Each category includes specific codes with descriptions and examples of their usage. The summary highlights the meaning of each code and the circumstances under which they are returned by the server.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Error Codes :

200 : request has succeeded .


201 : New resource got created .
204 : No Content (usually used after delete operation.)

400 : Bad request (wrong data/ invalida data in request).


401 : unauthorized (Invalid credentials are passed).
403 : Permission denied (even though passing correct credentials but not registered
to use it.)
404 : url incoorect or resource doesn't exist.
405 : method not allowed ( tried to perform post operation to a resource where only
get operation is enabled.)

500 : internal server error (server down)


502 : invalid gateway error (received an invalid response from an upstream server)
503 : service unavailable (temporarily unavailable to server overload or
maintanence of server.)
504 : gateway timeout ( delay in getting response from the upstream server.)

2xx Series – Success

200 OK
The request has succeeded. The meaning of the success depends on the HTTP method
used.
Example:

GET: The requested resource has been retrieved successfully.


POST: The data has been successfully submitted and processed by the server.
Example in Action:
A successful login request that returns a user dashboard.

HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "Login successful",
"user_data": { "name": "John", "age": 30 }
}

201 Created
The request has been fulfilled, and a new resource has been created. This is
typically used after a POST request.

Example in Action:
After submitting a form to create a new user, the server returns a 201 status code
along with the new user's ID.

HTTP/1.1 201 Created


Location: /users/123
Content-Type: application/json
{
"id": 123,
"name": "Jane Doe"
}

204 No Content
The server has fulfilled the request, but there is no content to send in the
response. Often used for DELETE requests.
Example in Action:
A request to delete an item returns a 204 status with no additional content.

HTTP/1.1 204 No Content

4xx Series – Client Errors : These codes indicate that the client seems to have
made an error.

400 Bad Request


The server cannot process the request due to a client error (e.g., malformed
request syntax, invalid request message framing).

Example in Action:
A user submits a form without filling out the required fields, and the server
responds with a 400 code.

HTTP/1.1 400 Bad Request


Content-Type: application/json
{
"error": "Missing required field: email"
}

401 Unauthorized
The request lacks valid authentication credentials or the credentials provided are
invalid.

Example in Action:
A user tries to access a protected resource without logging in.

HTTP/1.1 401 Unauthorized


WWW-Authenticate: Basic realm="User login"

403 Forbidden
The server understands the request but refuses to authorize it. Unlike 401,
authentication will not help.

Example in Action:
A user without proper permissions tries to access an admin dashboard.

HTTP/1.1 403 Forbidden


Content-Type: application/json
{
"error": "Access denied. You do not have the required permissions."
}

404 Not Found


The server cannot find the requested resource. This might happen if the URL is
incorrect or the resource doesn't exist.

Example in Action:
A user requests a webpage that has been deleted.

HTTP/1.1 404 Not Found


Content-Type: text/html
<html><body><h1>404 Not Found</h1></body></html>

405 Method Not Allowed


The HTTP method used is not supported for the requested resource.

Example in Action:
A user tries to POST data to a resource that only allows GET requests.

HTTP/1.1 405 Method Not Allowed


Allow: GET, HEAD

5xx Series – Server Errors : These codes indicate that the server has encountered
an error or is otherwise incapable of performing the request.

500 Internal Server Error


A generic error message indicating that something went wrong on the server side,
but the server cannot be more specific.

Example in Action:
A web application encounters an unexpected error while processing the request.

HTTP/1.1 500 Internal Server Error


Content-Type: application/json
{
"error": "An unexpected error occurred. Please try again later."
}

502 Bad Gateway


The server, while acting as a gateway or proxy, received an invalid response from
an upstream server.

Example in Action:
A reverse proxy server (e.g., Nginx) cannot get a valid response from an upstream
service.

HTTP/1.1 502 Bad Gateway


Content-Type: text/html
<html><body><h1>502 Bad Gateway</h1></body></html>

503 Service Unavailable


The server is currently unable to handle the request due to temporary overloading
or maintenance of the server.

Example in Action:
A website goes down temporarily due to server overload.

HTTP/1.1 503 Service Unavailable


Retry-After: 3600
Content-Type: text/html
<html><body><h1>503 Service Unavailable</h1></body></html>

504 Gateway Timeout


The server, while acting as a gateway or proxy, did not receive a timely response
from the upstream server.

Example in Action:
A proxy server does not receive a response from a backend service in time.

HTTP/1.1 504 Gateway Timeout


Content-Type: text/html
<html><body><h1>504 Gateway Timeout</h1></body></html>
Summary:
2xx (Success): The request was successful, and the server responded as expected.
4xx (Client Errors): The request contains errors, often due to bad input,
unauthorized access, or a non-existing resource.
5xx (Server Errors): The server failed to process the request due to an internal
issue or server overload.

You might also like