Use this curl API testing checklist to build repeatable requests, isolate client and server problems, and save useful evidence for debugging. It covers GET and POST requests, JSON, headers, authentication, cookies, redirects, TLS diagnostics, file uploads, response timing, retries, and shell-specific quoting.
Overview
curl is a practical command-line tool for testing REST APIs because it exposes the request directly: method, URL, headers, body, authentication, and connection options. That makes it useful before adding an endpoint to application code, when comparing environments, or when reproducing a production failure.
A good curl test answers two separate questions:
- Did the client send the request you intended?
- How did the server respond, including its status code, headers, body, and timing?
Start with the smallest working request and add one variable at a time. This prevents a malformed JSON body, missing header, shell expansion, or stale cookie from being mistaken for a server defect.
The examples below use POSIX-style shell syntax, commonly found on Linux and macOS. PowerShell and Windows Command Prompt have different quoting and line-continuation rules, so test a one-line version first when moving commands between platforms.
| Need to test | Useful curl options | What to preserve |
|---|---|---|
| Basic response | -i, -sS | Status, headers, response body |
| Request method and body | -X, -d | Method, content type, exact payload |
| Authentication | -H, -u, -b | Auth scheme, non-secret identifiers |
| Timing | -w | DNS, connection, TLS, and total time |
| Files | -F, --upload-file | Field name, file name, content type |
| Reproducibility | -o, -D, shell history controls | Response and request context without secrets |
Checklist by scenario
1. Test a GET endpoint
Begin with a simple request and show the response headers:
curl -i -sS https://api.example.test/v1/items-i includes response headers, while -sS keeps progress output quiet but still shows errors. Add query parameters explicitly and encode values when they contain spaces, ampersands, or other reserved characters:
curl -G -i -sS 'https://api.example.test/v1/items' \
--data-urlencode 'status=active' \
--data-urlencode 'limit=25'Using -G places data options in the URL as query parameters instead of creating a request body. Inspect the final URL and confirm that the API expects the parameter names and types you used.
2. Send a JSON POST request
For a JSON API, set the content type and provide a body that matches the endpoint schema:
curl -i -sS 'https://api.example.test/v1/items' \
-X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
--data '{"name":"Example item","enabled":true}'For larger or reusable payloads, put the JSON in a file. This reduces shell-quoting problems and makes the input easy to review:
curl -i -sS 'https://api.example.test/v1/items' \
-X POST \
-H 'Content-Type: application/json' \
--data @item.jsonValidate the JSON independently before testing the endpoint. A valid JSON document can still fail API validation if a required property, date format, nesting level, or data type is wrong.
3. Add bearer-token authentication
Send a bearer token in the authorization header. Prefer an environment variable rather than placing a live token directly in a command that may be stored in shell history:
export API_TOKEN='replace-with-a-short-lived-token'
curl -i -sS 'https://api.example.test/v1/profile' \
-H "Authorization: Bearer ${API_TOKEN}" \
-H 'Accept: application/json'Do not paste real tokens into tickets, screenshots, shared transcripts, or public repositories. If a token appears in captured output, redact it before sharing and follow the relevant credential-rotation process.
4. Test cookies and session behavior
For an existing cookie value, use a header or cookie option:
curl -i -sS 'https://api.example.test/v1/account' \
-H 'Cookie: session_id=redacted-value'To save cookies returned by one request and send them to another, use a cookie jar:
curl -i -sS -c cookies.txt 'https://api.example.test/login' \
-H 'Content-Type: application/json' \
--data '{"username":"demo","password":"redacted"}'
curl -i -sS -b cookies.txt 'https://api.example.test/v1/account'Treat the cookie jar as sensitive. It may contain session credentials even when the response body does not.
5. Follow redirects deliberately
Use -L when the endpoint is expected to redirect, such as an HTTP URL that moves to HTTPS:
curl -i -sS -L 'https://api.example.test/v1/items'When debugging authentication or request methods, first test without -L. The initial status and Location header can reveal whether the request reached the intended host. A redirect can also change how a client handles credentials or a non-GET method, so record the redirect chain rather than hiding it.
6. Diagnose TLS and connection problems
For certificate, hostname, protocol, or connection issues, enable verbose diagnostics:
curl -v 'https://api.example.test/health'Verbose output can include connection details and sensitive headers, so review it before sharing. Do not make certificate verification bypasses part of a normal test. Options that disable verification can help isolate a local certificate problem in a controlled environment, but they remove an important security check and should not be used as a production fix.
7. Upload a file
For a multipart form upload, use -F and match the server's field name:
curl -i -sS 'https://api.example.test/v1/uploads' \
-X POST \
-F 'description=Sample document' \
-F 'file=@./document.pdf'For a raw file upload, use --upload-file instead:
curl -i -sS 'https://api.example.test/v1/assets/example.pdf' \
-X PUT \
-H 'Content-Type: application/pdf' \
--upload-file './document.pdf'These are different request shapes. Confirm whether the API expects multipart form data or the file bytes as the complete request body.
8. Capture status and response timing
Use -w to print machine-readable measurements after the response. Send the body to a file so timing data stays separate:
curl -sS 'https://api.example.test/v1/items' \
-o response.json \
-w 'status=%{http_code}\ntime_total=%{time_total}\ntime_connect=%{time_connect}\ntime_starttransfer=%{time_starttransfer}\n'These values help distinguish an HTTP error from a connection delay or slow server response. Repeat the same request under comparable conditions before drawing conclusions from one measurement.
9. Retry cautiously
Retries can help with transient network failures, but repeating a request is not automatically safe. A repeated POST may create duplicate records unless the API supports idempotency keys or otherwise documents safe retry behavior. If retrying is appropriate, make the behavior explicit and record it:
curl -sS --retry 2 --retry-delay 1 \
'https://api.example.test/health'Use conservative retry settings for state-changing operations and avoid masking a persistent authentication, validation, or authorization failure.
What to double-check
- URL: Confirm the scheme, hostname, path, API version, query string, and environment.
- Method: Do not assume that adding
-dmatches the endpoint's required method. State-Xwhen clarity matters. - Headers: Check
Content-Type,Accept, authorization, tenant, request ID, and version headers. - Body: Validate JSON syntax, escaping, required fields, types, and encoding. Use a file for complex payloads.
- Status: Record the numeric HTTP status before interpreting the body. The [HTTP status code debugging guide](https://functions.top/http-status-codes-api-debugging-4xx-5xx) provides a useful next step for separating client and server responses.
- Environment: Compare base URLs, credentials, feature flags, proxy settings, and data between environments.
- Evidence: Save the sanitized command, timestamp, status, response headers, request ID, and response body when permitted.
A reusable API test template can look like this:
# 1. Set a non-production base URL and short-lived credential
BASE_URL='https://api.example.test'
API_TOKEN='redacted-or-loaded-securely'
# 2. Run the smallest request
curl -i -sS "${BASE_URL}/v1/resource" \
-H "Authorization: Bearer ${API_TOKEN}" \
-H 'Accept: application/json'
# 3. Add one change at a time
# method, query, body, header, cookie, redirect, or timing output
# 4. Record status, request ID, and sanitized responseCommon mistakes
- Shell quoting changes the payload. Single and double quotes behave differently, and characters such as
$,&, and backticks may be interpreted by the shell. Use a JSON file when a body contains nested quotes or shell-sensitive characters. - Confusing JSON with form data.
--datadoes not make a payload JSON by itself. Set the content type and send valid JSON, or use-Fwhen the endpoint expects multipart data. - Reading only the response body. A body may contain an error while the status, headers, and request ID explain the actual failure. Use
-ior save headers separately with-D headers.txt. - Following redirects too early.
-Lis convenient, but it can hide the first response and complicate authentication debugging. Inspect the initial response first. - Disabling TLS verification to make a test pass. Treat certificate errors as findings to investigate, not as a reason to remove verification from the workflow.
- Leaking credentials in diagnostics. Verbose mode, cookie jars, shell history, and captured headers can all contain secrets. Redact before sharing and clean up temporary files.
- Assuming a curl result proves application behavior. A successful command verifies one request path under one set of conditions. Add automated coverage with the project's test tools when the behavior is important; for example, use a mocking and spies workflow when testing client modules separately.
When to revisit
Return to this checklist whenever an endpoint changes method, schema, authentication mechanism, content type, redirect behavior, or deployment environment. Recheck it before filing an API bug, after changing a reverse proxy or TLS configuration, and when a request works in one environment but fails in another.
Review the command itself when your shell, operating system, curl version, or credential-handling workflow changes. Keep example payloads and test URLs non-production where possible, and replace obsolete flags or assumptions after reviewing the curl documentation used by your team.
For a practical incident workflow, begin with the smallest GET or health request, add authentication, reproduce the failing method and body, capture status and timing, then compare the result with browser network evidence or application logs. The [Chrome DevTools Network Panel guide](https://functions.top/chrome-devtools-network-panel-guide) can help when the same request succeeds or fails in a browser. Once the request is proven, turn the sanitized curl command into an automated API test so the evidence becomes repeatable rather than a one-time terminal session.