Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
GimmeJob
Sign in
Testing tools: hands-on guides · Chapter 03 / 09

Testing Tools

curl & jq

curl is the universal command-line HTTP client. It's preinstalled on macOS, most Linux distributions and Windows 10/11 (as curl.exe). A curl command is the most portable bug-report artifact: anyone can run it, it shows exactly what was sent, and it fits in a ticket or a CI script. jq is its natural partner. It reads JSON from curl and extracts, filters or checks the fields you care about.

Key factDetails
InstallUsually preinstalled. jq: brew install jq, sudo apt install jq, winget install jqlang.jq
Windows noteIn Windows PowerShell 5.1, curl is an alias for Invoke-WebRequest. Type curl.exe to get real curl
Best forMinimal reproductions, smoke checks, timing and TLS diagnostics, CI scripts
Practice APIhttps://postman-echo.com echoes your request back as JSON
Copy as cURL from DevTools (or write from scratch) → strip noise headers → curl -i / -v to see status and headers → add body, auth and cookies → jq to read the JSON → -w timing and --fail for scripts → paste the final command into the bug report

First requests: GET, status, headers and verbose mode

curl https://postman-echo.com/get?env=qa                 # body only
curl -i https://postman-echo.com/get?env=qa              # status line + headers + body
curl -I https://example.com                              # HEAD request: headers only
curl -v https://example.com                              # verbose: DNS, TLS, request and response headers
curl -L http://github.com                                # follow redirects (301/302)
curl -sS -o page.html https://example.com                # silent, but still show errors; save to a file
curl -s -o /dev/null -w "%{http_code}\n" https://postman-echo.com/status/404

How to read curl -v output:

  1. Lines starting with * are connection details: the IP address, TLS version, certificate and the negotiated HTTP version.
  2. Lines starting with > are the request exactly as sent: method, path, Host and the other headers.
  3. Lines starting with < are the response status and headers.
  4. The body follows after the headers.
QA tip: -w "%{http_code}" combined with -o /dev/null prints only the status code. That's the easiest way to check many URLs in a loop. On Windows use -o NUL.

Sending data: JSON, forms and file uploads

# JSON, short form (curl 7.82+): sets Content-Type and Accept to application/json
curl --json '{"name":"QA","role":"tester"}' https://postman-echo.com/post

# JSON, explicit form that works with any curl version
curl -X POST https://postman-echo.com/post \
  -H "Content-Type: application/json" \
  -d '{"name":"QA","role":"tester"}'

# JSON from a file, handy for long payloads
curl --json @payload.json https://postman-echo.com/post

# Classic HTML form (application/x-www-form-urlencoded)
curl -d "email=qa@example.test" -d "password=secret" https://postman-echo.com/post

# File upload (multipart/form-data)
curl -F "file=@screenshot.png" -F "comment=layout bug" https://postman-echo.com/post

# Other methods
curl -X PUT    --json '{"status":"done"}' https://postman-echo.com/put
curl -X DELETE https://postman-echo.com/delete

Quoting differs between shells. In bash and zsh, wrap JSON in single quotes. In Windows cmd.exe, use double quotes outside and escape the inner ones ("{\"name\":\"QA\"}"), or simply keep the JSON in a file and send it with @payload.json.

Caveat: -d without -X sends a POST. Adding -X GET to a command with -d sends a GET with a body, which many servers reject or ignore. Use -G if you want -d values in the query string instead.
# Bearer token from an environment variable, so it stays out of shell history
export TOKEN="paste-test-token-here"
curl -H "Authorization: Bearer $TOKEN" https://postman-echo.com/headers

# Basic auth (Postman Echo accepts postman / password)
curl -u postman:password https://postman-echo.com/basic-auth

# API key in a header
curl -H "x-api-key: $API_KEY" https://api.example.test/v1/items

# Save cookies the server sets, then send them back on the next call
curl -c cookies.txt "https://postman-echo.com/cookies/set?session=abc123"
curl -b cookies.txt https://postman-echo.com/cookies

The cookie jar (-c to write, -b to read) lets you script a real session: log in once, then call the protected endpoints with the same cookies.

QA tip: Negative auth checks are one-liners: drop the header (expect 401), send a garbage token (expect 401), or use a read-only user on a write endpoint (expect 403).

Timing and TLS diagnostics with -w, --resolve and timeouts

-w (--write-out) prints variables after the transfer. This breaks a slow request into its phases:

curl -s -o /dev/null https://example.com -w \
"dns:     %{time_namelookup}s
connect: %{time_connect}s
tls:     %{time_appconnect}s
ttfb:    %{time_starttransfer}s
total:   %{time_total}s
status:  %{http_code}  ip: %{remote_ip}  http: %{http_version}
"
VariableMeaning
time_namelookupDNS resolution finished
time_connectTCP connection established
time_appconnectTLS handshake finished (0 for plain HTTP)
time_starttransferFirst byte of the response arrived (TTFB)
time_totalWhole transfer finished

All values are cumulative from the start. A big gap between time_appconnect and time_starttransfer means the server is thinking, not the network.

# Hit a specific server behind a load balancer or before DNS is switched
curl --resolve api.example.test:443:10.0.0.5 https://api.example.test/health

# Fail fast instead of hanging
curl --connect-timeout 5 --max-time 20 https://api.example.test/slow

# Force a protocol version
curl --http1.1 https://example.com
curl --http2 https://example.com

# Show certificate details
curl -v https://example.com 2>&1 | grep -E "subject:|issuer:|expire date:"
Caveat: -k / --insecure skips certificate checks. It's acceptable on a throwaway local environment, but never "fix" a certificate bug with it. The certificate error is often the bug.

Reading JSON with jq

# Pretty-print
curl -s https://postman-echo.com/get?env=qa | jq .

# One field, raw string without quotes
curl -s https://postman-echo.com/get?env=qa | jq -r '.args.env'

# Field with a dash in the name
curl -s https://postman-echo.com/headers | jq -r '.headers["user-agent"]'

# Count items, pick fields, filter
jq '.items | length' response.json
jq '.items[] | {id, status}' response.json
jq '.items[] | select(.status == "failed") | .id' response.json

# Use jq as an assertion: exit code 1 if the expression is false or null
curl -s https://postman-echo.com/get?env=qa | jq -e '.args.env == "qa"' > /dev/null && echo PASS
jq filterDoes
.Whole document, pretty-printed
.user.emailNested field
.items[0]First array element
.items[]Each element in turn
select(.price > 100)Keep only matching elements
map(.id)Array of one field
keysField names of an object
-rRaw output (no quotes)
-eExit code reflects the result, useful in scripts

curl in scripts and CI: --fail, retries and exit codes

By default curl exits with code 0 even when the server returns 404 or 500, because the HTTP transfer itself worked. In scripts, ask curl to treat HTTP errors as failures:

# Exit code 22 on HTTP >= 400, and still print the error body
curl --fail-with-body -sS https://postman-echo.com/status/500

# Retry transient failures (connection errors, 408, 429, 5xx) 3 times, 2 s apart
curl --fail --retry 3 --retry-delay 2 -sS https://api.example.test/health

# Smoke check used in a pipeline
status=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/health")
[ "$status" = "200" ] || { echo "Health check failed: $status"; exit 1; }

From browser to terminal: in Chrome DevTools, right-click a request → Copy → Copy as cURL. Then delete headers that don't matter for the bug (sec-ch-ua, accept-language, tracking cookies). Keep the minimum that still reproduces the failure.

Chrome DevTools copy options for requests, including cURL
Official Chrome DevTools documentation screenshot: copy options for all requests, including Copy all as cURL.

Cheat sheet

TaskCommand
Show status and headerscurl -i URL
Debug connection and TLScurl -v URL
Follow redirectscurl -L URL
POST JSONcurl --json '{"a":1}' URL
Upload a filecurl -F "file=@a.png" URL
Bearer tokencurl -H "Authorization: Bearer $TOKEN" URL
Basic authcurl -u user:pass URL
Cookie session-c jar.txt then -b jar.txt
Only the status codecurl -s -o /dev/null -w "%{http_code}" URL
Timing breakdown-w "%{time_starttransfer} %{time_total}"
Pin DNS to one server--resolve host:443:10.0.0.5
Fail the script on HTTP errors--fail-with-body
Extract a JSON fieldcurl -s URL piped into jq -r '.field'
Hands-on lab: a 20-line smoke-check script with curl and jq

Save the script below as smoke.sh, run chmod +x smoke.sh, then run ./smoke.sh. You need bash (macOS, Linux, WSL or Git Bash) and jq.

  1. Read the script first. It calls three endpoints, checks the status and one JSON field, and prints the timing.
  2. Run it. All three lines should start with PASS.
  3. Change the expected value in the first check to stage and run it again. Confirm that the script prints FAIL and exits with code 1 (echo $?).
  4. Replace BASE with your own test environment and the checks with your real endpoints. This is the start of a deployment smoke test.
#!/usr/bin/env bash
set -u
BASE="https://postman-echo.com"
fail=0

check() {  # name, url, jq-expression-that-must-be-true
  local body status time
  body=$(curl -sS -w '\n%{http_code} %{time_total}' "$2") || { echo "FAIL $1 (connection)"; fail=1; return; }
  status=$(tail -n1 <<<"$body" | cut -d' ' -f1)
  time=$(tail -n1 <<<"$body" | cut -d' ' -f2)
  if [ "$status" = "200" ] && sed '$d' <<<"$body" | jq -e "$3" >/dev/null; then
    echo "PASS $1  ${time}s"
  else
    echo "FAIL $1  status=$status  ${time}s"; fail=1
  fi
}

check "query echo"  "$BASE/get?env=qa"   '.args.env == "qa"'
check "headers"     "$BASE/headers"      '.headers | has("user-agent")'
check "status 200"  "$BASE/status/200"   '.status == 200'
exit $fail

Extension: add a fourth check for $BASE/status/503. The server answers 503, so the script prints FAIL for that line and exits with code 1, which is exactly what should stop a deployment.

Official curl documentation · jq manual

Summary

  • -i and -v show exactly what went over the wire. Use them before guessing.
  • --json, -d and -F cover JSON, forms and uploads. -H, -u and the cookie jar cover authentication.
  • -w timing variables separate DNS, connect, TLS, server time and download. --resolve and timeouts help with environment and network issues.
  • jq turns curl into a test: extract fields with -r and assert with -e. In CI, always use --fail-with-body so HTTP errors fail the job.

Source registry

Verified 22 Nov 2026
curl documentation

Command-line HTTP requests, data, auth, cookies, write-out variables, TLS and retry options

curl · verified
Source ↗
jq manual

jq filters, select/map, raw output (-r) and exit-status mode (-e)

jq project · verified
Source ↗
MDN HTTP reference

HTTP methods, headers, status codes and request/response semantics

Mozilla · verified
Source ↗
Chrome DevTools Network features reference

Network filters, Preserve log, throttling presets, Copy as cURL, edit and resend, HAR export

Google Chrome · verified
Source ↗