HTTP/1.1 Status Codes Overview
1. Introduction
HTTP status codes are issued by a server in response to a client's request made to the server. They represent the outcome of the request and provide information about what happened during the process.
2. Status Codes
HTTP/1.1 defines a set of status codes that can be grouped into five categories. Each status code is a three-digit number, and the first digit indicates the response type.
2.1 List of Common Status Codes
- 200 OK: The request has succeeded.
- 201 Created: The request has succeeded, and a new resource has been created.
- 204 No Content: The server successfully processed the request, but is not returning any content.
- 400 Bad Request: The server could not understand the request due to invalid syntax.
- 401 Unauthorized: The request requires user authentication.
- 403 Forbidden: The server understands the request, but refuses to authorize it.
- 404 Not Found: The server can't find the requested resource.
- 500 Internal Server Error: The server encountered a situation it doesn't know how to handle.
3. Categories of Status Codes
Status codes are categorized into five classes based on the first digit of the code:
- 100-199: Informational responses
- 200-299: Successful responses
- 300-399: Redirection messages
- 400-499: Client error responses
- 500-599: Server error responses
4. Best Practices
4.1 Guidelines
- Use
200 OK
for successful GET requests. - Use
201 Created
for POST requests that create resources. - Return
204 No Content
for successful requests that do not return data. - Utilize
404 Not Found
for unknown endpoints. - Log unexpected status codes for debugging and monitoring.
5. FAQ
What does a 404 error mean?
A 404 error indicates that the server can't find the requested resource. It is often displayed when a user tries to access a page that doesn't exist.
How do I handle 500 errors?
500 errors are server-side errors. They can be caused by various issues, such as server misconfigurations or application errors. Ensure to log these errors for further investigation.