REST API debugging becomes much faster when you treat every failed request as a comparison problem: what did the client send, what did the server receive, and what response did the server return? This reusable workflow shows how to investigate HTTP errors with curl, Postman, and HTTPie, isolate authentication, validation, routing, rate-limit, and server failures, and capture a reproducible request for an integration test or production investigation.
Overview
Before changing application code, reduce the failing API call to a small set of observable facts. Record the HTTP method, complete URL, query parameters, request headers, request body, response status, response headers, response body, and elapsed time. A client-side failure can come from any layer: an incorrect URL, a missing authorization header, invalid JSON, an unexpected redirect, a proxy, a rate limit, or a server-side exception.
Use one tool to create a minimal reproducible request and another, if useful, to inspect the request interactively. The goal is not to find the “best” API debugging tool. The goal is to make the request explicit and repeatable.
| Tool | Best use | Useful strengths | Watch for |
|---|---|---|---|
| curl | Reproduction, scripts, CI, and server-side checks | Available on many systems, precise flags, easy to save in documentation | Shell quoting and hidden environment differences |
| Postman | Organizing collections and inspecting requests interactively | Visible headers, bodies, variables, authentication settings, and response details | Inherited variables or automatic behavior can hide what was sent |
| HTTPie | Readable manual testing from a terminal | Concise syntax and human-friendly request and response output | Commands may not translate directly to another client without checking headers and body encoding |
Checklist by scenario
1. Establish a known-good request shape
Start with the smallest request that should work. Confirm the HTTP method and URL separately from the payload. Check spelling, path parameters, query parameters, and whether the API expects a trailing slash or a version segment. Do not assume that a browser URL and an API URL behave the same way.
curl --request GET \
--url 'https://api.example.test/v1/items?limit=10' \
--header 'Accept: application/json' \
--include \
--silent \
--show-error
--include displays response headers, while --silent --show-error keeps output readable without suppressing connection errors. Add --verbose when you need connection and request-level diagnostics, but avoid sharing verbose output if it contains credentials or sensitive data.
2. Investigate authentication and authorization errors
For a 401 or 403 response, verify the authentication scheme, token value, required scopes or roles, and the environment in which the token was issued. Check that the header is actually present in the outgoing request and that a variable did not resolve to an empty or stale value.
curl --request GET \
--url 'https://api.example.test/v1/profile' \
--header "Authorization: Bearer $API_TOKEN" \
--header 'Accept: application/json' \
--include
Decode a token only to inspect non-secret claims such as an issuer, audience, subject, or expiry. Decoding does not verify a token's signature. For a deeper token troubleshooting workflow, see the JWT Decoder Guide. Never paste live credentials into tickets, public collections, shell history, or online tools.
3. Investigate validation and JSON body errors
A 400 or 422 response often means the server received the route but rejected the request shape or values. Compare the expected field names, data types, required fields, enum values, date format, and nesting. Send an explicit content type and inspect the response body for field-level details.
curl --request POST \
--url 'https://api.example.test/v1/orders' \
--header 'Authorization: Bearer REDACTED' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '{"customerId":"cust_123","items":[{"sku":"part-7","quantity":2}]}' \
--include
In Postman, open the request's Headers and Body views rather than relying only on a saved example. Confirm that the selected body mode is raw JSON and that the active environment contains the intended base URL and token. In HTTPie, an equivalent request can be written as:
http POST https://api.example.test/v1/orders \
"Authorization:Bearer $API_TOKEN" \
customerId=cust_123 \
items:='[{"sku":"part-7","quantity":2}]'
4. Investigate 404, 405, and redirect responses
A 404 can mean a wrong path, an unknown resource identifier, or a deliberate response that conceals resource existence. A 405 usually points to an incorrect HTTP method. For both, compare the request with the API contract and test the exact URL outside the application.
Redirects deserve special attention. Use curl --include first to see the Location header. Add --location only when following redirects is intentional:
curl --location --request GET \
--url 'https://api.example.test/v1/items/42' \
--header 'Accept: application/json' \
--write-out '\nstatus=%{http_code} time=%{time_total}s\n'
Following a redirect can change the effective URL and may affect how credentials or methods are handled. Capture the final URL and status when reporting the issue.
5. Investigate rate limits and transient failures
A 429 response indicates that the server is asking the client to slow down. Inspect response headers for retry guidance and log the request time, endpoint, and response identifiers. Do not respond by adding unlimited retries. Use bounded retries with backoff, preserve idempotency where appropriate, and avoid retrying validation or authentication failures.
For 5xx responses, first determine whether the same request fails consistently. A single failure may be transient; a repeatable failure should be reported with a sanitized request, response body, timestamp, and correlation or request ID. Measure timing to distinguish a quick rejection from a timeout:
curl --request GET \
--url 'https://api.example.test/v1/health' \
--connect-timeout 5 \
--max-time 20 \
--write-out '\nstatus=%{http_code} dns=%{time_namelookup}s connect=%{time_connect}s total=%{time_total}s\n' \
--silent \
--show-error
What to double-check
- Headers: Confirm
Authorization,Accept,Content-Type, tenant or workspace headers, and any required idempotency key. Compare casing only when relevant to the system; focus primarily on presence and value. - Body encoding: Ensure the payload is valid JSON, not a string containing escaped JSON or form data sent with a JSON content type. A JSON formatter can help inspect structure, but validate against the API contract as well.
- Variables: Review active Postman environments, shell variables, CI secrets, and base URLs. Print non-sensitive variable names and resolved endpoints when debugging configuration.
- Response evidence: Save the status, headers, body, request ID, and timing. Redact tokens, cookies, personal data, and confidential payload fields before sharing.
- Network path: Check proxies, VPNs, TLS errors, DNS resolution, and corporate gateways when a request never reaches the expected service. A timeout is not the same as an HTTP error.
- Pagination and state: If the endpoint returns partial data, verify cursor or offset parameters and inspect the next-page link. The API Pagination Patterns guide covers common pagination failure modes.
Use a status-code decision checklist: 2xx means inspect whether the returned data is semantically correct; 3xx means inspect redirect behavior; 4xx means compare the request with authentication, routing, and validation requirements; 429 means apply server-directed throttling; and 5xx or a timeout means investigate service health, dependencies, and network conditions.
Common mistakes
Changing several variables at once: Altering the URL, token, body, and client together removes the evidence needed to identify the cause. Change one dimension, then repeat the request.
Trusting a successful status alone: A 200 response can still contain an application-level error, stale data, or an empty result caused by a filter. Check the response schema and business meaning.
Copying a request without reviewing secrets: Postman exports, verbose curl logs, and browser captures can include bearer tokens, cookies, and personal data. Redact before committing or sharing.
Retrying non-idempotent operations blindly: Repeating a POST after a timeout can create duplicate work unless the API supports an idempotency mechanism or the operation can be safely checked first.
Assuming the client is at fault: Reproduce the request with a second client, but do not treat different output formatting as proof of different behavior. Compare the actual method, URL, headers, body, and redirect path.
When to revisit
Return to this workflow whenever an endpoint, authentication method, proxy, API version, client library, or deployment environment changes. Review saved curl commands and Postman collections before integration-test cycles and before seasonal planning or release work, especially if variables, secrets, rate limits, or test data have changed.
Keep one sanitized, minimal request for each important endpoint. Give it a clear purpose, document required variables, and record expected status and response shape. When a failure occurs, run the checklist in order: reproduce, capture, classify the status, compare the request, test with a second client if needed, and only then change application code. This turns API debugging from trial and error into a repeatable developer productivity practice.