HTTP Requests and Responses, Explained

Understand methods, status codes, headers, and the request-response cycle behind websites and APIs.

By Rishipal Singh · · 5 min read

An HTTP request travels to a server and returns with a status and response.
Visual guide: An HTTP request travels to a server and returns with a status and response.

HTTP is the protocol browsers and web servers use to exchange requests and responses. A page load may involve many of these exchanges: HTML first, then stylesheets, images, scripts, and API data.

A request describes what you want

An HTTP request includes a method, a path, headers, and sometimes a body. GET commonly retrieves a resource. POST commonly submits data to create or process something. Headers carry details such as content type, caching preferences, and authorization.

A response describes what happened

The response contains a status code, headers, and sometimes a body. Codes in the 2xx range indicate success, 3xx indicate redirection, 4xx indicate a client-side issue, and 5xx indicate a server-side failure. For example, 404 means the requested resource was not found.

HTTP is stateless

Each request can be understood independently; the protocol does not automatically remember earlier requests. Applications can associate requests with sessions using cookies or tokens when needed.

HTTP semantics matter when building APIs and caches. Choose methods and status codes that describe the actual behavior, and avoid sending sensitive data over unencrypted connections. HTTPS protects HTTP traffic in transit using TLS.

Practice: interpret an HTTP response

A server returns HTTP status 404. What does that status communicate?

Reveal the explanation

404 means the server could not find a representation for the requested resource. It is a client-error response, not a successful page response.