Kodokon kodokon.com

HTTP in plain sight: methods and status codes

Read a real request and a real response, and learn what 200, 404 and 500 actually mean.

8 min · 3 questions

Open this lesson in Kodokon

HTTP (HyperText Transfer Protocol) is the language the browser and the server speak to each other. Good news: it is not incomprehensible binary, it is readable text. A request fits in a few lines: a verb, an address, then headers that fill in the context (which language I prefer, which browser I am using). The response follows the same shape: a numeric code, headers, a blank line, then the content.

BASH
curl -i https://example.com

HTTP/2 200
content-type: text/html; charset=UTF-8
content-length: 1256
cache-control: max-age=86400

<!doctype html>
<html>
...
The -i option tells curl to print the response headers too, not just the content.

The verb at the start of a request is called a method, and it announces your intent. GET simply asks to read a resource: that is what the browser does every time you open a page. POST sends data to the server, typically when you submit a signup form. PUT updates an existing item, and DELETE asks for it to be removed. Focus on the first two: they account for the overwhelming majority of all traffic.

BASH
curl -X POST -d "name=Sarah&age=30" https://httpbin.org/post
A POST request: -d supplies the data being sent, just as a form would.

Every response starts with a three-digit status code. The first digit alone tells you the situation. Codes in the 2xx range mean success: 200 means "here is what you asked for". The 3xx codes are redirects: 301 means "this page has moved, go over there instead". The 4xx codes point to an error on the client side: 404 (resource not found), 403 (access forbidden), 401 (you need to sign in). The 5xx codes point to a failure on the server side: 500 is the classic internal error.

BASH
curl -I https://example.com/this-page-does-not-exist

HTTP/2 404
content-type: text/html; charset=UTF-8
The -I option (capital i) asks for headers only: perfect for checking a status code.

Knowledge check

Make sure you remember the key points of this lesson.

  1. What does a 404 status code mean?
    • The server has crashed
    • The requested resource cannot be found at that address
    • The request succeeded
  2. Which family of codes signals a problem on the server side?
    • The 2xx
    • The 3xx
    • The 4xx
    • The 5xx
  3. Which HTTP method does the browser use to simply read a page?
    • GET
    • POST
    • DELETE