HTTP Response Structure and Status Codes
What you'll learn: How HTTP servers structure their responses and what the different status code ranges tell you about request outcomes.
The Response Format
When a web server answers your HTTP request, it sends back a response with three main parts:
- Status Line: Contains the HTTP version, a numeric status code, and a brief reason phrase (e.g.,
HTTP/1.1 200 OK) - Headers: Metadata about the response (content type, length, caching rules, etc.)
- Body: The actual content—HTML, JSON, an image, or other data (optional)
Think of it like receiving a package: the shipping label tells you if delivery succeeded (status line), the packing slip has details (headers), and the box contains your item (body).
Status Code Categories
Status codes are three-digit numbers grouped by their first digit:
-
2xx (Success): Request succeeded. Example:
200 OKmeans "here's your data,"201 Createdmeans "resource created successfully." -
3xx (Redirection): The resource moved or you need to go elsewhere. Example:
301 Moved Permanentlysays "this page is now at a different URL,"304 Not Modifiedmeans "use your cached copy." -
4xx (Client Error): You made a mistake. Example:
404 Not Foundmeans the URL doesn't exist,403 Forbiddenmeans you don't have permission. -
5xx (Server Error): The server failed to fulfill a valid request. Example:
500 Internal Server Errormeans the server crashed processing your request,503 Service Unavailablemeans it's temporarily overloaded.
Key Takeaway: HTTP responses always include a status code in the 2xx–5xx range that tells you at a glance whether your request succeeded (2xx), needs redirection (3xx), had a client-side problem (4xx), or encountered a server failure (5xx).