← Back to the map

Unit 1 · Lesson 3

HTTP and HTTPS

Almost everything your phone does online is the same tiny conversation: "Please give me this." "Here you go." Repeated billions of times a second.

By the end you can

Watch

Prefer reading? The same lesson is written out below.

HTTP is the language browsers, apps and servers speak. It's a simple request and response: the client asks, the server answers.

GET /cart200 OKBrowserInternetWeb server
A browser sends an HTTP request (method, path, headers) over an encrypted TLS connection to a web server, which replies with a status code, headers and a body.

The request

GET /cart HTTP/1.1
Host: shop.example.com
Authorization: Bearer abc123
Accept: application/json

The response

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: max-age=60

{"items": 3, "total": 42.50}

A status code, headers, and usually a body.

Methods and status codes

MethodMeaningOK to retry (idempotent)?
GETRead somethingYes
POSTCreate something, or "do this action"Not by default
PUTReplace something at this pathYes
PATCHChange part of somethingNot always
DELETERemove somethingYes

Idempotent means doing it twice has the same effect as doing it once. That matters when a network call times out: you can retry a PUT without harm, but retrying a POST /payments might charge someone twice. (HTTP also has a stricter word, safe, for methods that change nothing at all, like GET. PUT and DELETE are idempotent but not safe.)

Status codes come in families: 2xx success (200 OK, 201 Created), 3xx go elsewhere (301 Moved Permanently), 4xx the client did something wrong (400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests), 5xx the server failed (500 Internal Server Error, 503 Service Unavailable).

HTTP is stateless: each request stands alone, and the server doesn't remember the last one. Things like "logged in" are carried in every request, usually as a cookie or a token. That's what lets any of your servers handle any request.

HTTPS

HTTPS is HTTP inside an encrypted TLS connection. It gives you:

Setting up TLS costs an extra round trip or so when connecting, so connections are kept open and reused. Today every site should use HTTPS; browsers warn users about plain HTTP.

Key idea: HTTP is a stateless request (method, path, headers, body) and response (status, headers, body). Know which methods are safe to retry and what each status family means. HTTPS adds encryption, integrity and server identity.

Check yourself

Which of these are part of an HTTP request? (Pick all that apply.)

Your new flashcards

Practice them now. With a free account they come back in your daily review.

Card 1 of 4