Skip to the workspace
Pebellslearn by building
How the Web Works  ›  Lesson

HTTP — Requests and Responses

What is HTTP? 14 minHTTP is a request and response conversation in which the client names a method and a path and the server replies with a status code, headers and an optional body.

backend / HTTP — Requests and Responses

Explore each scene at your own pace.

01 · The rule

The rule

HTTP — Requests and Responses

Packets get bytes to your server, but the bytes need a shared language. When a shopper opens book 42, the browser and your backend have a short, strictly structured conversation. That language is HTTP, and almost everything a backend developer builds is an answer to an HTTP request.

The rule

The client asks with a method and path; the server answers with a status.

A request has a method, a path, headers and sometimes a body:

GET /books/42 HTTP/1.1
Host: bookshop.example
Accept: application/json

A response has a status code, headers and usually a body:

HTTP/1.1 200 OK
Content-Type: application/json

{"id": 42, "title": "The Salt Road", "price": 399}

The method says what the client wants to do:

Method Meaning
GET read something, change nothing
POST create something, or trigger an action
PUT replace something completely
PATCH change part of something
DELETE remove something

Headers are Name: value lines about the message, such as Content-Type (what format the body is in) or Authorization (who is asking).

The status code is a three-digit verdict, and its first digit tells you the family:

  • 2xx success: 200 OK, 201 Created, 204 No Content
  • 3xx go elsewhere: 301 Moved Permanently, 304 Not Modified
  • 4xx the client got something wrong: 400 Bad Request, 401 Unauthorized, 404 Not Found
  • 5xx the server failed: 500 Internal Server Error, 503 Service Unavailable

HTTP is stateless: each request must carry everything the server needs, because the server does not remember the previous one by itself. Logins work by sending a cookie or token again with every request. HTTPS is the same HTTP carried inside an encrypted TLS connection.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.