HTTP, HTTPS and TLS
Learn the request-response model, methods, status codes, headers, cookies, HTTP versions and how TLS secures HTTPS connections.
Beginner · about 5 hours · difficulty 2/5
Learn first: DNS
HTTP is the application protocol of the web and of most APIs, so it matters in networking rounds, backend interviews and system design alike.
The basics
- A request has a method, path, headers and optional body; a response has a status code, headers and body.
- Methods: GET (read), POST (create), PUT (replace), PATCH (partial update), DELETE. Know which are safe and idempotent (GET, PUT and DELETE are idempotent; POST is not).
- Status codes: 2xx success (200, 201, 204), 3xx redirect (301, 302, 304), 4xx client errors (400, 401 vs 403, 404, 409, 429), 5xx server errors (500, 502, 503).
- HTTP is stateless. State is added with cookies, sessions or tokens (JWT).
- Useful headers:
Content-Type,Authorization,Cache-Control,ETag,Set-Cookie, CORS headers.
Versions
- HTTP/1.1: persistent connections (keep-alive), but one request at a time per connection.
- HTTP/2: multiplexing many streams over one TCP connection, header compression.
- HTTP/3: runs over QUIC (UDP) to avoid TCP head-of-line blocking.
HTTPS and TLS
- HTTPS is HTTP inside TLS, which gives confidentiality, integrity and authentication.
- The TLS handshake: the client and server agree on a cipher, the server proves its identity with a certificate signed by a trusted CA, and they derive shared symmetric keys (asymmetric crypto is used only to set up the session because it is slow).
- Know symmetric vs asymmetric encryption, hashing, and what a digital signature proves.
Related
REST basics, WebSockets for two-way communication, and cookies vs local storage for auth tokens.
Good enough to move on: you can explain 401 vs 403, why PUT is idempotent but POST is not, and the purpose of each step of the TLS handshake.
Key concepts
- Request and response structure
- HTTP methods and idempotency
- Status codes
- Headers, cookies and sessions
- HTTP/1.1 vs HTTP/2 vs HTTP/3
- TLS handshake and certificates
- Symmetric vs asymmetric encryption
- WebSockets
Mini project
Build a tiny HTTP/1.1 server on raw TCP sockets that parses a request line and headers and serves static files with correct status codes and Content-Type, then inspect a real HTTPS site's certificate chain in your browser and explain each certificate.
Check yourself
Why does TLS use asymmetric cryptography during the handshake but symmetric cryptography for the rest of the connection?
Free resources
- MDN: An overview of HTTP (MDN)
- Cloudflare Learning Center: What is TLS? (Cloudflare)
- High Performance Browser Networking (Ilya Grigorik)