SystemTutor
About
Sign in
Loading course documentation…
SystemTutor

COURSES

  • Data Structures & Algorithms
  • CSS MasterclassNew course
  • System DesignNew course

PRACTICE

  • Algorithm practice
  • CSS practice

LEGAL

  • Privacy Policy
  • Terms of Service
  • About

© 2026 SystemTutor. All rights reserved.

Built with 🫶 by Shatlyk

System design
How a Request Crosses a NetworkIPTCPUDP Routing, streams, and datagramsDNSHTTP Requests and Responses From a hostname to an HTTP response
Networking

HTTP Requests and Responses

Learn how HTTP requests and responses work, what methods and status codes tell you, when a retry is safe, and what HTTPS protects.

HTTP (Hypertext Transfer Protocol) defines how clients and servers exchange requests and responses. A request uses a method such as GET or POST to describe the requested action. The response uses a status code such as 200 OK or 201 Created to describe the outcome. These meanings are defined in RFC 9110, HTTP Semantics.

Lesson goal

Inspect a request and its response, explain what HTTPS protects, and decide when repeating a request is safe.

Before you begin — DNS.

After resolving a hostname and opening a connection, a browser can use HTTP to ask for a page or submit data. HTTP/1.1 and HTTP/2 commonly use TCP. HTTP/3 uses QUIC over UDP.

Read a request and response together

Suppose an app wants to create a user. It sends POST /users to the API, sets Content-Type: application/json, and includes the user details in the body. The server creates the record and replies with 201 Created. Its response can include a Location header identifying the new resource and a body containing the representation.

A request carries a method, path, headers, and optional body. The response carries a status, headers, and optional body.

In this exchange the app is the client because it initiated the request. If the API calls another service to finish the work, the API is a client in that second exchange.

const response = await fetch("https://api.example.com/users", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ username: "alice" }),
});

console.log(response.status, response.headers.get("Location"));

The hostname in these examples is illustrative. To study a real exchange, open the Network panel in your browser’s developer tools and reload a page. Select a request and read its target and method, the request headers and optional payload, then the response status, headers, and body. A 204 No Content response ends after its headers.

The browser network panel lists individual requests with their status, type, size, and duration.

Interpret the method and status together

MethodWhat the client requestsExample
GETRetrieve a representation.Read /users/42.
POSTAsk the target to process the submitted data.Create a user through /users.
PUTCreate or replace the state at a particular URI, if allowed by the API.Store the complete profile at /users/42.
PATCHApply the supplied changes to the target.Set one field on the profile.
DELETERemove the association between the target URI and its current functionality.Remove access to /users/42.

An HTTP status code describes the outcome of this exchange. 1xx reports interim progress, 2xx success, 3xx redirection or cache-related outcomes, 4xx a problem fulfilling this request, and 5xx a server-side failure. Read the specific code. A 404 says the target was not found or its existence was withheld. A 503 says the service is temporarily unavailable. Neither tells you exactly what happened inside a database. HTTP semantics

Reason about a lost response

The server may finish a request even when the client never receives the reply. A method is idempotent when repeating an identical request has the same intended effect as sending it once. GET, PUT, and DELETE have this property. Two identical DELETE calls can receive different responses, such as a successful deletion followed by 404, while leaving the resource in the same final state.

A POST /users that creates a user on every call could create two users after a retry. For PATCH, inspect the operation. Setting a field to a fixed value can be idempotent. Incrementing it by one changes the result each time. The API contract must tell the client how to handle an uncertain outcome.

Protect an exchange with HTTPS

HTTPS uses Transport Layer Security (TLS) to authenticate the server and protect HTTP data in transit from disclosure or alteration. During a typical first connection, the client checks the server’s certificate and the peers establish keys for protected traffic. The receiving service can then read the request and apply its own access rules.

TLS protects the HTTP request and response exchanged over an HTTPS connection.

Check your understanding

A client sends a complete profile with PUT /users/42. The connection fails before it receives a response. What does the failure tell the client, and what does the method tell it?

Compare your reasoning

The connection failure leaves the outcome unknown. If the API implements PUT as specified, resending the same representation asks for the same final state. The first attempt may already have succeeded, so the two response codes could differ.

Key Takeaways

  • Requests identify a target and operation. Responses describe the outcome through a status, headers, and optional content.
  • Idempotence concerns the intended effect of repeating a request. The observed replies can differ.
  • HTTPS protects HTTP traffic between TLS endpoints. The service still decides who may perform the requested action.

Take the quiz · From a hostname to an HTTP response

How is this lesson?

Previous lessonDNSNext lesson From a hostname to an HTTP response
Edit on GitHubReport on GitHub
On this page
%

On this page

Read a request and response togetherInterpret the method and status togetherReason about a lost responseProtect an exchange with HTTPSCheck your understandingKey Takeaways