HTTP Status Codes and Their Categories
HTTP status codes are standard response codes issued by a server to indicate the result of a client's request. These codes are grouped into five categories based on the nature of the response:
1. Informational Responses (1xx)
The 1xx status codes are provisional responses that indicate the server has received the request and is processing it.
- Common Codes:
- 100 Continue: The server has received the request headers and the client can proceed to send the request body.
- 101 Switching Protocols: The server is switching protocols as requested by the client.
2. Successful Responses (2xx)
The 2xx status codes indicate that the request was successfully received, understood, and processed by the server.
- Common Codes:
- 200 OK: The request was successful, and the response contains the requested data.
- 201 Created: A new resource has been successfully created.
- 204 No Content: The request was successful, but there is no content to return.
3. Redirection Messages (3xx)
The 3xx status codes indicate that the client must take additional actions to complete the request, such as following a redirect.
- Common Codes:
- 301 Moved Permanently: The requested resource has been permanently moved to a new location.
- 302 Found: The resource is temporarily located at a different URI.
- 304 Not Modified: The resource has not been modified since the last request.
4. Client Error Responses (4xx)
The 4xx status codes indicate that there was an error with the client's request.
- Common Codes:
- 400 Bad Request: The server cannot process the request due to a client error.
- 401 Unauthorized: Authentication is required to access the resource.
- 403 Forbidden: The server understood the request but refuses to authorize it.
- 404 Not Found: The requested resource could not be found.
5. Server Error Responses (5xx)
The 5xx status codes indicate that the server encountered an error while processing the request.
- Common Codes:
- 500 Internal Server Error: The server encountered an unexpected condition that prevented it from fulfilling the request.
- 502 Bad Gateway: The server received an invalid response from an upstream server.
- 503 Service Unavailable: The server is currently unavailable, often due to maintenance or overload.
Summary
HTTP status codes are essential for understanding the outcome of client-server interactions. Familiarity with these codes helps in debugging and ensuring proper handling of API responses.