Web protocol fundamentals

How HTTP Requests and Responses Work

Follow an HTTP exchange from URL through method, headers, body, status, caching, and browser handling.

How this page is maintained

Written for learners, checked against the sources below, and reviewed every year. Last reviewed July 27, 2026.

Short answer

HTTP is an application protocol built around request and response messages. A client sends a method, target, headers, and sometimes a body. A server returns a status, headers, and sometimes a body. The protocol defines message meaning, while DNS, TLS, connections, caches, proxies, and application code determine how an exchange actually reaches a user.

Who this is for: Frontend, backend, and full-stack developers who can call an API but want to reason clearly about what crosses the network.

  • Read method, target, headers, body, and status as one contract rather than isolated values.
  • Separate HTTP semantics from transport, encryption, browser policy, and application behavior.
  • Use browser network tools and server logs together when diagnosing an exchange.

A request states an intended operation

A request begins with a method and a target. GET asks for a representation, POST submits data for processing, PUT replaces a target representation, PATCH requests a partial change, and DELETE requests removal. These names do not enforce business rules by themselves. Server code still decides whether a caller may act and whether the target exists.

Headers carry metadata such as accepted media types, credentials, conditional validators, and content length. A body may contain JSON, form fields, bytes, or another representation. Do not send secrets in a URL query because URLs commonly appear in history and logs. Validate content type and size before parsing untrusted bodies.

A response reports an outcome

The response status class gives a broad result: informational, successful, redirection, client error, or server error. A 404 means the selected resource was not found, while a 500 means the server failed unexpectedly. Status alone is rarely enough for an application, so a stable error body can add a machine code and safe explanation.

Response headers describe the returned representation and how it may be used. Content-Type tells the recipient how to interpret bytes. Cache-Control sets reuse policy. ETag supports conditional requests. Set-Cookie asks a user agent to store a cookie under browser rules. These fields affect behavior after application code returns.

Connections and intermediaries matter

Before HTTP messages travel, a client normally resolves a host, establishes a connection, and negotiates TLS for HTTPS. A connection may carry multiple exchanges depending on the HTTP version. Reverse proxies, content delivery networks, gateways, and corporate proxies can terminate encryption, cache content, rewrite headers, or route to another service.

That path explains why the same application can behave differently in local and production environments. A proxy may impose a body limit or timeout that application tests never exercise. Preserve a request identifier across trusted hops, document which proxy sets client-address headers, and avoid trusting forwarding headers from arbitrary internet clients.

Browsers add their own security model

JavaScript does not receive every network response freely. Same-origin policy and CORS control whether a browser exposes a cross-origin response to script. Cookie rules may depend on origin, site, SameSite, Secure, and credentials settings. A successful server log therefore does not prove that browser code was allowed to consume the result.

Debug from both ends. In developer tools, inspect the final URL, request headers, status, response headers, timing, and any preflight request. On the server, correlate the same exchange using a safe identifier. Reproduce with a command-line client only to isolate browser policy, not to conclude that browser behavior should match it.

Trace a profile update

A browser sends a profile change to an HTTPS API and the interface reports that the save failed.

  1. Inspect the PATCH request target, JSON Content-Type, credentials behavior, and body without copying sensitive values into a ticket.
  2. Confirm whether an OPTIONS preflight ran and whether the API returned the required origin, method, and credential headers.
  3. Match the request identifier to server logs, then distinguish validation rejection from an unexpected exception.
  4. Check the final status and structured error code, and make the interface handle that documented outcome.
Result: The team finds that the API updated correctly in a command-line test but the browser blocked the response because the credentialed CORS policy was incomplete.

HTTP exchange inspection card

Record these fields before changing code during an HTTP investigation.

  • Request: method, final URL, media type, relevant safe headers, body shape, and request identifier.
  • Path: DNS host, HTTPS termination, proxy or CDN, destination service, timeout, and size limits.
  • Response: status, media type, cache policy, cookie instructions, CORS headers, and error code.
  • Client handling: redirect, cache hit, preflight, credential mode, parsing, retry, and displayed state.
  • Evidence: browser capture, correlated server event, expected contract, and smallest reproducible request.

Common mistakes

  • Treating every failed fetch as a server outage without checking browser policy or response parsing.
  • Returning 200 for errors and forcing each client to infer success from prose in the body.
  • Logging authorization headers, session cookies, or full sensitive request bodies while debugging.

Try one

A POST appears as successful in server logs, but browser JavaScript reports a network error. What evidence would you collect, and what explanations would you test first?

A reasoned answer compares the browser request, any OPTIONS preflight, response headers, redirect chain, and server event using one identifier. It tests CORS and credential rules, TLS or proxy failure, and blocked mixed content before changing business logic. It also explains that a command-line success isolates browser policy but does not prove the web integration is correct.

Sources

Learn this with a tutor

Tell LearnLive what you already know and what you need to do with http requests and responses.

Build this course