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 3 of 6 · Lab · 20 min · revision 3

Lab: Inspecting Traffic with curl and DevTools

Use curl and the browser Network panel to see real exchanges: status lines, headers and bodies, methods and errors, TLS details, HTTP versions and content negotiation.

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.
  • Choose the HTTP method for an operation and interpret status code classes, stating which methods are safe and which are idempotent.
  • 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. Goal and setup

In this lab you send real requests from a terminal and from a browser, and read every part of the exchange: status line, headers, body, method, TLS details and HTTP version. You will use two public services: httpbin.org, which echoes back what you send so you can see your own request from the server's side, and api.github.com, GitHub's REST API, which needs no account for the calls below.

You need:

  • curl 7.76 or later, for --fail-with-body; curl 7.82 or later also has the --json shortcut. macOS, Windows 10 and 11, and most Linux distributions include curl. In Windows PowerShell, type curl.exe, because PowerShell 5.1 maps curl to a different command. If the quoting in the JSON examples causes trouble on Windows, use Git Bash or WSL.
  • A desktop browser with developer tools: Chrome, Edge or Firefox.
  • Internet access. If httpbin.org is down, run the same service locally with docker run -p 8080:80 kennethreitz/httpbin and use http://localhost:8080 in place of https://httpbin.org (there is no TLS in that case).

Check your curl version first. The output throughout was recorded with curl 7.81 on Linux. Blocks captioned Illustrative output show dates, IDs, IP addresses and header lines that will differ on your machine, though the structure will not; blocks captioned Expected output should match exactly.

Terminal
curl --version
Illustrative output (first lines, trimmed; yours shows your own curl build)
curl 7.81.0 (x86_64-pc-linux-gnu) libcurl/7.81.0 OpenSSL/3.0.2 zlib/1.2.11 ...
Release-Date: 2022-01-05
Protocols: dict file ftp ftps gopher gophers http https imap imaps ...
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 ...

02. Step 1: Read a whole response with -i

Ask httpbin for /get with one query parameter. -i (--include) prints the status line and response headers before the body. Put the URL in quotes, because ? and & mean something to your shell.

Terminal
curl -i 'https://httpbin.org/get?lang=en'
Illustrative output (your date, IP address and trace ID differ)
HTTP/2 200
date: Sat, 17 Oct 2026 13:34:01 GMT
content-type: application/json
content-length: 284
server: gunicorn/19.9.0
access-control-allow-origin: *
access-control-allow-credentials: true

{
  "args": {
    "lang": "en"
  },
  "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.81.0",
    "X-Amzn-Trace-Id": "Root=1-6ad37949-00abfe08677b32a503fb64f3"
  },
  "origin": "198.51.100.123",
  "url": "https://httpbin.org/get?lang=en"
}

Read it from the top. The status line says curl and the server agreed on HTTP/2 and the request succeeded. HTTP/2 sends header names in lower case. content-type: application/json tells you how to parse the body, and content-length gives its size in bytes.

The body is httpbin describing the request it received: your query string parsed into args, and the headers curl added on its own. Accept: */* means any format is acceptable. origin is your public IP address as the server saw it.

03. Step 2: See both directions with -v

-v (--verbose) shows the connection, the TLS handshake and both sets of headers. Verbose output goes to standard error, so discard the body with -o /dev/null (-o NUL in Windows cmd or PowerShell) to keep the screen readable.

Terminal
curl -v -o /dev/null https://httpbin.org/get
Illustrative output (TLS lines trimmed; addresses and certificate details vary)
*   Trying 98.89.203.252:443...
* Connected to httpbin.org (98.89.203.252) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
...
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=httpbin.org
*  subjectAltName: host "httpbin.org" matched cert's "httpbin.org"
*  issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M01
*  SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
> GET /get HTTP/2
> Host: httpbin.org
> user-agent: curl/7.81.0
> accept: */*
>
< HTTP/2 200
< date: Sat, 17 Oct 2026 13:34:07 GMT
< content-type: application/json
< content-length: 256
< server: gunicorn/19.9.0
...
* Connection #0 to host httpbin.org left intact

Lines that start with * are curl's own notes about the connection: the IP address it reached, the TLS version, the certificate checks and the result of ALPN, where curl offered h2 and http/1.1 and the server chose HTTP/2. Lines that start with > are the request curl sent, and lines that start with < are the response headers. Newer curl versions word some notes differently (for example ALPN: server accepted h2), but the three prefixes are the same.

Treat verbose output as sensitive. It prints every request header in full, so a command with an Authorization header or a cookie prints the secret too. Redact it before you paste output into a ticket or a chat.

04. Step 3: Change the method, headers and body

Send JSON to httpbin's /post endpoint. -X sets the method, -H adds a header and -d sends a body. With -d, curl already uses POST, so -X POST only makes the intent explicit. Without the Content-Type header, curl would label the body as form data. On curl 7.82 or later, --json '{"title": "hello"}' sets the body and both JSON headers in one option.

Terminal
curl -i -X POST https://httpbin.org/post \
  -H 'Content-Type: application/json' \
  -d '{"title": "hello"}'
Illustrative output (some lines trimmed; content-length varies with your headers)
HTTP/2 200
content-type: application/json
content-length: 434
...

{
  "args": {},
  "data": "{\"title\": \"hello\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Content-Length": "18",
    "Content-Type": "application/json",
    ...
  },
  "json": {
    "title": "hello"
  },
  ...
}

httpbin parsed your body into json because the Content-Type said it was JSON. Now use a method that the /get endpoint does not support:

Terminal
curl -i -X POST https://httpbin.org/get
Illustrative output (recorded against httpbin.org; some headers trimmed)
HTTP/2 405
content-type: text/html
content-length: 178
server: gunicorn/19.9.0
allow: OPTIONS, HEAD, GET
...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>

405 Method Not Allowed comes with an Allow header listing the methods that do work. Notice that this error body is HTML, not JSON: one more reason to check Content-Type before parsing.

05. Step 4: Make curl fail on HTTP errors

Ask GitHub for a repository that does not exist. -w (--write-out) prints the status code, -s hides the progress meter and -S keeps real errors visible. Then print the exit code of curl itself.

Terminal
curl -sS -o /dev/null -w '%{http_code}\n' \
  https://api.github.com/repos/encode/no-such-repo-xyz
echo "exit code: $?"
Expected output
404
exit code: 0

The server said 404, yet curl exited with 0: from curl's point of view the transfer worked. A script that checks only the exit code would carry on as if nothing were wrong. --fail-with-body makes curl exit with code 22 for any status of 400 or above, while still printing the error body so you can log it:

Terminal
curl -sS --fail-with-body https://api.github.com/repos/encode/no-such-repo-xyz
echo "exit code: $?"
Expected output
{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/repos/repos#get-a-repository",
  "status": "404"
}
curl: (22) The requested URL returned error: 404
exit code: 22

curl has no overall time limit by default. --max-time caps the whole operation in seconds. httpbin's /delay/5 waits five seconds before it answers:

Terminal
curl -sS --max-time 2 https://httpbin.org/delay/5
echo "exit code: $?"
Expected output
curl: (28) Operation timed out after 2000 milliseconds with 0 bytes received
exit code: 28

Exit code 28 means a timeout. Every call your own code makes needs a limit like this; you will set one in httpx and in fetch in the next lesson.

06. Step 5: Negotiate a format and check the HTTP version

httpbin's /image endpoint chooses an image format from your Accept header. Try three values and print only the status and the Content-Type the server chose:

Terminal
for type in image/png image/webp application/json; do
  curl -s -o /dev/null -H "Accept: $type" \
    -w "$type -> %{http_code} %{content_type}\n" https://httpbin.org/image
done
Expected output
image/png -> 200 image/png
image/webp -> 200 image/webp
application/json -> 406 application/json

The server honoured each image type and answered 406 Not Acceptable when you would accept only JSON, which it cannot produce for an image. Now compare HTTP versions. %{http_version} prints the version curl used, and -I sends a HEAD request to read headers only:

Terminal
curl -s -o /dev/null -w '%{http_version}\n' https://httpbin.org/get
curl -s -o /dev/null -w '%{http_version}\n' --http1.1 https://httpbin.org/get
curl -sI https://www.cloudflare.com | grep -i alt-svc
Expected output
2
1.1
alt-svc: h3=":443"; ma=86400

The first request negotiated HTTP/2 through ALPN; --http1.1 forced the older version. The third command found an Alt-Svc header offering HTTP/3 on port 443. To send an HTTP/3 request yourself, your curl must list HTTP3 under Features in curl --version; many system builds do not, and you do not need it for this course.

07. Step 6: The same exchange in browser DevTools

  1. Open https://httpbin.org/ in Chrome, Edge or Firefox.
  2. Open the developer tools with F12 (Cmd+Option+I on macOS) and select the Network panel. It records only while the tools are open.
  3. Switch to the Console panel and run the two lines below. They call the same site, so no cross-origin rules get in the way, and print the query parameters httpbin received.
  4. Go back to Network and click the request named get?from=devtools. The Headers tab shows the request URL, method, status code and remote address, then the response headers and the request headers the browser sent. The Response tab (and Preview in Chrome) shows the body.
  5. Right-click any column heading in the request list and turn on Protocol. It shows h2, h3 or http/1.1 for each request.
  6. Right-click the request and choose Copy, then Copy as cURL (in Firefox: Copy Value, then Copy as cURL). Paste the command into your terminal and run it: curl sends the same request and gets the same response.
Browser Console (JavaScript)
const response = await fetch('/get?from=devtools');
(await response.json()).args;
Expected output (Chrome; Firefox lays it out slightly differently)
Console:
{from: 'devtools'}

Network panel, with the Protocol column turned on:
Name                Status   Type    Protocol
get?from=devtools   200      fetch   h2

The browser sent more headers than curl did, such as Accept-Language, Referer and Sec-Fetch-*, and httpbin echoes them all back. Copy as cURL includes cookies and every other header the browser sent. On a site where you are signed in, that means your session, so treat the copied command like a password.

08. Troubleshooting

09. Check your understanding

Practice check · 3 questions

Reading tool output

Questions about the commands and panels you have just used.

Q1. In curl -v output, where do you see whether the server's certificate was accepted?
Q2. A deploy script calls a health endpoint with curl. It must stop when the endpoint answers 500 and keep the error body in the log. Which option does that?
Q3. You used Copy as cURL on a request from your signed-in session and want to paste the command into a bug ticket. What should you do first?
Practice only: not graded, not saved, not evidence.

10. Apply it: stretch task

Measure where the time goes. curl can print timings with -w. Run the command below three times as it is and three times with --http1.1 added, and compare the time to connect, the time to finish the TLS handshake and the time to the first byte of the response (ttfb). All three are measured from the start of the request.

Terminal
curl -s -o /dev/null https://httpbin.org/get -w \
  'connect %{time_connect}s  tls %{time_appconnect}s  ttfb %{time_starttransfer}s\n'
Example output (your times will differ)
connect 0.271721s  tls 0.760910s  ttfb 0.987734s

Then open a large website with the Network panel and its Protocol column visible, and find at least one request served over h3. You may need to reload, because browsers often switch to HTTP/3 only after they have seen Alt-Svc.

If your work involves a keyed API, such as a language-model provider, inspect one call with -v using a key read from an environment variable, and practise redacting the Authorization line from the output before you share it.

11. Review prompt

Without looking back, name the curl option for each job: include the response headers, show the request headers and TLS details, set a header, send a JSON body, fail on an HTTP error but keep the body, and limit the total time. Then say where in DevTools you would find the HTTP version of a request, and how you would replay that request in a terminal.

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