Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 20 min · revision 3

What Travels Over the Wire: Requests, Responses and HTTPS

Read an HTTP exchange part by part, see what HTTPS protects, how HTTP/1.1, HTTP/2 and HTTP/3 use connections, and how Accept and Content-Type agree on a format.

Contentsand lesson path

What you will learn

  • Identify the parts of an HTTP request and response (method, URL, headers, body, status) and inspect them with curl or browser developer tools.
  • Explain what HTTPS adds to an exchange (encryption, integrity and server authentication by certificate), how HTTP/1.1, HTTP/2 and HTTP/3 differ in connection use, and how Accept and Content-Type negotiate a representation.

Prerequisites: Python Foundations

01. Why it matters

Every time a browser loads a page, a mobile app syncs, or your code calls a payment service or a large language model, two programs exchange HTTP messages. Libraries hide the details until something goes wrong: a 401 you did not expect, an HTML page where you asked for JSON, a call that hangs, or a certificate error on a company network.

At that point you need to read the exchange itself. Is the problem in what you sent, in the network between you and the server, or in the server's answer? This lesson gives you the vocabulary: the parts of a request and a response, what HTTPS adds, how the three HTTP versions in use today carry the same messages in different ways, and how client and server agree on a format. The rest of this skill builds on it.

02. Anatomy of a request and a response

HTTP is a request–response protocol. A client connects to a server and sends a request; the server sends back one final response. Both messages have the same three parts: a start line, a block of header fields, and an optional body (RFC 9110 calls the body content).

The request below creates a note through a JSON API. It is written in the HTTP/1.1 text format because that is the easiest to read; later sections explain how newer versions carry the same information.

An HTTP/1.1 request: start line, headers, blank line, body
POST /v1/notes?draft=true HTTP/1.1
Host: api.example.com
User-Agent: curl/8.5.0
Accept: application/json
Content-Type: application/json
Authorization: Bearer <token>
Content-Length: 26

{"title": "Read RFC 9110"}
  • The request line holds the method (POST), the request target (the path /v1/notes plus the query string ?draft=true) and the protocol version.
  • Headers are Name: value pairs that describe the message. Names are case-insensitive, which is why tools often show them in lower case. Host names the server, Accept lists the formats the client wants back, Content-Type labels the body and Authorization carries credentials.
  • A blank line ends the headers. What follows is the body, and Content-Length gives its size in bytes. A GET request normally has no body.

The response has the same shape. Its start line is the status line: the version, a three-digit status code and a short reason phrase. Code should act on the number; the phrase is only there for people.

The response: status line, headers, blank line, body
HTTP/1.1 201 Created
Content-Type: application/json
Location: /v1/notes/42
Content-Length: 36

{"id": 42, "title": "Read RFC 9110"}

The URL you pass to a library is taken apart before anything is sent. In https://api.example.com/v1/notes?draft=true#top, the scheme https selects HTTP over TLS and the default port 443; the host api.example.com is used to find and verify the server and goes into the Host header; the path and query string become the request target; and the fragment #top never leaves the client.

HTTP is stateless: each request stands on its own, and any state travels in headers. A website can store a small value in the browser with a Set-Cookie response header, such as Set-Cookie: session=abc123; Secure; HttpOnly; SameSite=Lax, and the browser returns it in a Cookie header on later requests to that site. Code that calls an API usually sends a token in the Authorization header instead.

03. What HTTPS adds

HTTPS is HTTP sent inside a TLS connection. Before any HTTP message moves, client and server run a TLS handshake to agree on keys. From then on, TLS gives the exchange three properties:

  1. Confidentiality. The whole HTTP message is encrypted: method, path, query string, headers, cookies, tokens and body. An observer on the same Wi-Fi, or your internet provider, can still see which IP address you connect to, how much data moves and when, and usually the server's host name, which travels in the handshake and in DNS lookups.
  2. Integrity. Every encrypted record carries an authentication tag, so data altered in transit is detected and rejected instead of being accepted silently.
  3. Server authentication. The server presents a certificate for its host name, signed by a certificate authority (CA) that your operating system or runtime trusts. The client checks the signature chain, the validity dates and that a name in the certificate matches the host in the URL. This is what stops someone in the middle from posing as the API.

HTTPS does not identify the user (logins and tokens do that), does not make the server's own code trustworthy and does not protect data once it is stored. curl, httpx, fetch and browsers verify certificates by default. When verification fails, find out why and fix the certificate or the trust store. Switching verification off throws away server authentication, and encryption to a party you cannot identify protects very little.

Part of curl -v https://httpbin.org/get (curl 7.81): the certificate checks
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=httpbin.org
*  start date: Jun 19 00:00:00 2026 GMT
*  expire date: Jan  2 23:59:59 2027 GMT
*  subjectAltName: host "httpbin.org" matched cert's "httpbin.org"
*  issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M01
*  SSL certificate verify ok.

The excerpt shows all three checks passing: the name matches the host, today's date falls between the start and expiry dates, and the chain leads to a trusted issuer. This server chose TLS 1.2; many servers now negotiate TLS 1.3. You will produce output like this yourself in the lab.

04. HTTP/1.1, HTTP/2 and HTTP/3

Methods, status codes and headers mean the same in every version, because RFC 9110 defines them once for all of them. The versions differ in how messages are framed and how they share connections.

  • HTTP/1.1 sends messages as text. A connection stays open for reuse, but it carries one request and its response at a time, so a slow response holds up whatever is queued behind it. Browsers work around this by opening several connections to the same host, typically up to six.
  • HTTP/2 (RFC 9113) sends the same messages as binary frames and multiplexes many concurrent streams over a single TCP connection, with compressed headers. Header names travel in lower case, which is why curl prints content-type rather than Content-Type. Its weak spot is TCP itself: one lost packet holds back every stream until it has been resent.
  • HTTP/3 (RFC 9114) keeps the multiplexed streams but runs over QUIC (RFC 9000), a transport built on UDP with TLS 1.3 inside it. Streams are independent at the transport level, so a lost packet delays only its own stream, and a new connection needs fewer round trips before the first request.

Client and server pick the version without any work from you. Over TLS, they agree on HTTP/2 or HTTP/1.1 during the handshake through an extension called ALPN: that is the ALPN, server accepted to use h2 line in the excerpt above. A server that also speaks HTTP/3 advertises it in an Alt-Svc response header, and the client may switch to QUIC for later requests. The connection in use does not change, and the ma (max age) parameter says how many seconds the client may remember the offer.

A server offering HTTP/3 on port 443, remembered for 86,400 seconds
$ curl -sI https://www.cloudflare.com | grep -i alt-svc
alt-svc: h3=":443"; ma=86400

In your own code this is mostly invisible. Browsers use HTTP/2 or HTTP/3 whenever the server offers them. curl uses HTTP/2 for HTTPS when it was built with HTTP/2 support. httpx speaks HTTP/1.1 unless you install its optional HTTP/2 extra and pass http2=True. The version rarely changes your logic, but it explains differences in performance and is worth recording when you debug.

05. Content negotiation with Accept and Content-Type

One resource can have several representations: JSON or CSV, English or Vietnamese, compressed or not. Content negotiation lets the client say what it can use and the server choose.

  • Accept, on a request, lists the media types the client can handle, optionally weighted: Accept: application/json, text/csv;q=0.5 means JSON is preferred and CSV is acceptable.
  • Content-Type, on any message with a body, labels that body. On a request it tells the server how to parse what you sent; on a response it tells you how to parse what came back.
  • Other pairs work the same way: Accept-Language with Content-Language, and Accept-Encoding with Content-Encoding for compression such as gzip or br.

If the server cannot produce anything you accept, it may answer 406 Not Acceptable or simply send its default format. If it cannot read the body you sent, it usually answers 415 Unsupported Media Type or a validation error. A response that varies with these headers should include Vary: Accept (or the header concerned) so that caches keep the variants apart.

The client prefers JSON; the server picks it and labels the body
GET /v1/reports/7 HTTP/1.1
Host: api.example.com
Accept: application/json, text/csv;q=0.5

HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept

{"id": 7, "rows": 1250}

The practical rule for your code: check the status code and the Content-Type before you parse the body. Error pages from proxies and load balancers, and login pages from expired sessions, are often HTML, even when the API behind them only ever returns JSON.

06. Check your understanding

Practice check · 3 questions

Read the wire

Three situations you will meet when you read real traffic.

Q1. A script calling https://reports.internal.example fails with a certificate verification error. The server belongs to your company. What is the right fix?
Q2. A response over HTTP/2 carries alt-svc: h3=":443"; ma=86400. What does this header let the client do?
Q3. Your code expects JSON. A response arrives with status 200 and Content-Type: text/html. What is the sensible reading?
Practice only: not graded, not saved, not evidence.

07. Apply it

Pick an HTTPS API you use, or https://httpbin.org/get if you have none. Run curl -v against one read-only endpoint and, from the output, write down:

  • the request line and three request headers, with what each header is for;
  • the status line, the Content-Type of the response and the size of the body;
  • the TLS version, the certificate subject and issuer, and the HTTP version that was negotiated.

If the API needs a key, as a model provider's API does, read it from an environment variable, for example -H "Authorization: Bearer $API_KEY". curl -v prints every request header, so redact the Authorization line before you share the output.

08. Review prompt

Without looking back, write out the raw request and response for reading note 42 from https://api.example.com/v1/notes/42 as JSON, headers included. Then list three things HTTPS protects and two it does not, and explain in two sentences why HTTP/3 moved from TCP to QUIC.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check