HTTP status codes¶
HTTP status codes are numerical codes issued by a web server in response to a client's request. They are essential for troubleshooting production traffic and understanding the outcome of HTTP interactions^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
These codes are categorized based on the type of response, indicating whether a request was successful, redirected, resulted in a client error, or encountered a server-side issue.
2xx Success¶
The 2xx class of status codes indicates that the client's request was successfully received, understood, and accepted^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
- 200 OK: The standard response for successful HTTP requests^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md]. When a route is accessed successfully, logs will typically show a
200status code^[400-devops__09-Scripting-Language__python__introduction__part-4.http__README.md].
4xx Client Errors¶
The 4xx class of status codes indicates that the client appears to have made an error^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
- 400 Bad Request: The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax)1. For example, sending data with broken JSON format will trigger a
400code, signaling the client to send correctly formatted data^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md]. - 404 Not Found: This status code indicates that the requested resource was not found on the server^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md]. A common scenario is attempting to access a specific item (like a customer ID) that does not exist in the database^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
- 405 Method Not Allowed: This code is returned when the method specified in the request line (e.g.,
GETorPOST) is not allowed for the resource identified by the request URI^[400-devops__09-Scripting-Language__golang__introduction__part-3.http__readme.md]. For instance, accessing aPOST-only endpoint via a browser (which defaults toGET) will result in a "Method Not Allowed" error^[400-devops__09-Scripting-Language__python__introduction__part-4.http__README.md].
5xx Server Errors¶
The 5xx class of status codes indicates that the server is aware that it has erred or is incapable of performing the requested method^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
- 500 Internal Server Error: This is a generic error message indicating an unexpected condition was encountered and no more specific message is suitable^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md]. Common causes include unhandled exceptions in code, such as a
KeyErrorwhen trying to access a dictionary key that does not exist^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
Implementation¶
In web applications, such as those built with [[Flask]] (Python) or the standard net/http package ([[Go]]), status codes are often explicitly set within the route handlers to manage the flow of data and error reporting^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
For example, instead of returning a blank object for a missing resource, an application should explicitly return a 404 code to accurately reflect the state^[400-devops-09-scripting-language-python-introduction-part-4http-readme.md].
Related Concepts¶
- HTTP Methods
- [[API]]
Sources¶
400-devops-09-scripting-language-python-introduction-part-4http-readme.md400-devops__09-Scripting-Language__golang__introduction__part-3.http__readme.md400-devops__09-Scripting-Language__python__introduction__part-4.http__README.md
-
Inferred definition from source context describing "Malformed request syntax". ↩