Frontend Labs
⋯

Part IV — HTTP, networking, and the browser

25. HTTP fundamentals for JS developers

Every fetch() call is an HTTP request under the hood: a method, a URL, a set of headers, and an optional body — the response mirrors that shape with a status code, headers, and a body.

const res = await fetch("https://api.example.com/users/42", {
  method: "GET",
  headers: { "Accept": "application/json" },
});
res.status;        // 200
res.ok;             // true for 200-299
res.headers.get("content-type");
const data = await res.json();

Status code classes you'll branch on constantly: 2xx success, 3xx redirect (handled transparently by fetch unless redirect: "manual"), 4xx client error (your request was wrong — don't blindly retry), 5xx server error (often safe to retry with backoff, §31).

For the full HTTP/TCP/TLS mechanics underneath this — handshakes, headers, keep-alive — see wiki/networking/tcp-ip/real-life-example.md; this section stays focused on what's specifically relevant from JS.

Generated from real-life-JS-guide.md · 8 Oct 2026 16:36