Track 01 · Lesson 4 of 9How the web works

Track 01 · How the web works

HTTP methods and status codes

Lesson 4 of 9· 7 min

Every request has a method (what you want to do) and every response has a status code (how it went). Pick a situation to see the real messages browsers and servers exchange.

Read the real messages

Pick a situation

Request (browser to server)

GET /products/42 HTTP/1.1Host: shop.example.comAccept: text/htmlCookie: session=7f3a9c

Response (server to browser)

HTTP/1.1 200 OKContent-Type: text/html; charset=utf-8Cache-Control: max-age=60<!doctype html><html lang="en">…

GET asks for something without changing anything. 200 OK means it worked, and the page is in the body.

  • 1xxHold on, still working
  • 2xxSuccess, here you go
  • 3xxLook somewhere else
  • 4xxYou asked wrong
  • 5xxThe server failed

The methods you'll actually use#

  • GET reads something. It should never change anything.
  • POST creates something, like an order or a comment.
  • PUT replaces something entirely. PATCH changes part of it.
  • DELETE removes something.
  • HEAD is a GET without the body: "just tell me about it".

Two words worth knowing. A method is safe if it never changes anything: GET and HEAD. It's idempotent if sending it twice has the same effect as once: GET, PUT and DELETE are, POST isn't. That's why browsers warn you before resubmitting a form.

401 versus 403#

These two get mixed up constantly, even by experienced developers:

  • 401 Unauthorized means "we don't know who you are". Logging in can fix it.
  • 403 Forbidden means "we know exactly who you are, and the answer is still no".

Despite its name, 401 is about authentication (who you are), and 403 is about authorization (what you may do). You'll meet that pair properly in Identity and login.

Check yourself

A server answers 403 Forbidden. What does it mean?