Lesson 3: The response envelope: status code and what it means
Lesson objectives:
- Read the status line of an HTTP response.
- Place a status code into the correct class.
- Explain whether a response body is present.
The server replies with a three-digit number
The server's answer is also an envelope. The first line of that envelope is the status line, and it always begins with a three-digit status code. That number is the server's way of saying, "I understood your request," or "I could not find that," or "I broke while trying." 12
Explanation
The status line
A typical response starts like this:
HTTP/1.1is the protocol version.200is the status code.OKis the reason phrase, a short human-readable label. The reason phrase is informational; the number is what matters 12.
Status code classes
The first digit of the status code tells you the class:
- 1xx — Informational (rare for beginners to see)
- 2xx — Success, e.g.
200 OK3 - 3xx — Redirection, e.g.
301 Moved Permanently - 4xx — Client error, e.g.
404 Not Found4 - 5xx — Server error, e.g.
500 Internal Server Error5
A status code is not a random error message. It is a standard category.
The response body
After the headers, the response may include a body: the actual HTML, image, JSON, or other data the browser asked for. Some responses, like 204 No Content, have no body because the answer is already complete in the status code and headers 1.
Worked example (follow along)
Here is a successful response to a GET request:
- Status code:
200(success) Content-Type: text/htmltells the browser the body is HTML.Content-Length: 1276tells the browser how many bytes to expect.- The body is the HTML page.
Now here is a 404 response:
The server is working; it just does not have the page the browser asked for.
Your turn (faded example)
Match each status code to its class:
Summary + what's next
The response starts with a status code. The first digit tells you the class: 2xx success, 3xx redirect, 4xx client error, 5xx server error. After the status line and headers, the response may carry a body. Next, you will learn where to read all of this inside your browser.
Footnotes
-
MDN: HTTP messages — https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Messages ↩ ↩2 ↩3
-
MDN: HTTP response status codes — https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status ↩ ↩2
-
MDN: 200 OK — https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/200 ↩
-
MDN: 404 Not Found — https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/404 ↩
-
MDN: 500 Internal Server Error — https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/500 ↩