Skip to article content
FrontendXLesson 03 / 20

HTTP Requests and Responses

Build an accurate mental model of what the browser does, from navigation and HTTP through parsing, rendering, storage, workers, security, and DevTools, so you can predict behavior and debug real pages.

beginner · about 30 minutes · 2 exercises

  • Predict
  • Explain

What you will be able to do

#
  • Describe the structure of an HTTP request and response.
  • Choose an appropriate method and status code.
  • Explain how keep-alive and HTTP/2 affect request behavior.

Overview

#

Every resource on a page is fetched over HTTP. Understanding the message shape explains most Network panel behavior.

Request

A request has a method, a target, headers, and an optional body. Common methods: GET (safe, cacheable), HEAD, POST, PUT, PATCH, DELETE. GET and HEAD should be safe and idempotent.

Response

A response has a status code, headers, and a body. Status classes: 1xx informational, 2xx success, 3xx redirect, 4xx client error, 5xx server error. 304 Not Modified means the cached copy is still valid.

Headers that matter

  • Content-Type tells the browser how to interpret the body.
  • Content-Encoding names compression such as gzip or br.
  • Cache-Control controls caching.
  • Set-Cookie stores cookies, subject to SameSite rules.
  • Access-Control-Allow-Origin controls cross-origin reads.

Connections

HTTP/1.1 keeps connections alive and limits parallel requests per host. HTTP/2 multiplexes many streams over one connection, so request count matters less than bytes and priority.

Questions to carry forward

  • Which methods are idempotent?
  • What does Content-Encoding: br mean?
  • How does HTTP/2 change request prioritization?

Exercises

#

Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.

  1. Exercise 1Predict

    A client sends a conditional GET with If-None-Match matching the server's current ETag. What status comes back and what body?

    Choose the best answer
  2. Exercise 2Explain

    Explain the difference between safe and idempotent methods, with an example of each combination.

    Reveal the reference answer
    reference.text
    Safe means no side effects (GET, HEAD). Idempotent means repeating the request has the same effect as sending it once (GET, PUT, DELETE). PUT is idempotent but not safe because it changes state. POST is neither.

    Authored expected output: An answer distinguishing safe from idempotent with a concrete method.

    Safety is about read-only behavior; idempotency is about repeatability. PUT and DELETE are idempotent but not safe.

Common misconceptions

#
  • GET requests can safely have side effects.
  • A 304 response carries a full body.
  • HTTP/2 still opens one connection per request.

Follow-up practice

#
  • browser-internals-http-caching
  • browser-internals-storage-apis

Related resources

#

Your progress

#

Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.

Verification: authored. Answers and outputs on this page are authored reference material, not executed results.

© 2026 FrontendX. All rights reserved.