API Debugging Workflow: Diagnose HTTP Errors, Headers, CORS, and Request Bodies
APIsHTTPCORScurlbackend development

API Debugging Workflow: Diagnose HTTP Errors, Headers, CORS, and Request Bodies

UUnbound Dev Hub
2026-11-30
8 min read

A reusable API debugging checklist for HTTP errors, headers, CORS, authentication, request bodies, pagination, and response parsing.

When an API request fails, the fastest solution is usually not changing code at random. This reusable API debugging workflow helps you isolate the failing layer—URL, method, headers, authentication, request body, browser policy, or server logic—using reproducible requests, response evidence, and focused checklists.

Overview

API debugging becomes difficult when several variables change at once. A request may work in an API client but fail in a browser, return a successful status with the wrong data, or produce a generic error that hides a malformed body. Treat the request as a set of independently testable parts:

  • Target: scheme, host, port, path, query string, and API version.
  • Method: GET, POST, PUT, PATCH, DELETE, or another method supported by the endpoint.
  • Headers: authentication, content negotiation, content type, tracing, and caching instructions.
  • Body: valid syntax, required fields, correct types, and an encoding the server expects.
  • Execution context: browser, command line, test runner, server process, proxy, or API client.
  • Server behavior: routing, validation, authorization, database access, downstream calls, and error handling.

Change one category at a time and preserve the exact request that produced the failure. A copied URL, request header set, body, timestamp, response status, and response body are more useful than a description such as “the endpoint does not work.” Avoid recording secrets in tickets or logs; redact tokens and credentials before sharing examples.

HTTP status codes as starting points

Status codes narrow the investigation, but they do not explain every failure. Read the response body and server logs alongside the status.

Code or classTypical meaningFirst checks
2xxThe server handled the request successfully.Verify the response shape, returned data, side effects, and client parsing.
3xxThe request involves a redirect or another representation.Inspect the Location header and confirm whether the client follows redirects.
400The request is invalid or cannot be processed as sent.Check syntax, required fields, query parameters, and the documented input format.
401Authentication is missing, invalid, or not accepted.Check the token, scheme, expiry, environment, and exact authorization header.
403The server understood the request but refuses access.Check user, role, scope, tenant, resource ownership, and server policy.
404The route or requested resource was not found.Compare host, base path, API version, URL encoding, identifier, and HTTP method.
405The route exists but does not allow that method.Confirm the endpoint contract and inspect the Allow header if supplied.
409The request conflicts with current resource state.Check duplicate identifiers, version conflicts, and state-transition rules.
415The server does not support the submitted media type.Compare Content-Type with the body format expected by the endpoint.
422The structure may be readable, but validation failed.Parse field-level errors and check types, ranges, formats, and required values.
429The client has sent too many requests for the applicable limit.Inspect retry guidance, request volume, concurrency, and backoff behavior.
5xxThe server or an upstream dependency failed.Check server logs, correlation IDs, deployment changes, timeouts, and dependency health.

Checklist by scenario

1. Reproduce the request outside the application

Start with a minimal request that can be run repeatedly. This separates API behavior from frontend state, client middleware, and application code.

curl --request POST 'https://api.example.test/v1/items?dryRun=true' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer REDACTED_TOKEN' \
  --data '{"name":"Example item","enabled":true}' \
  --include

The --include option displays response headers as well as the body. Add verbose output only when needed, because it can expose connection details and request metadata. For a GET request, remove the body and use the method expected by the endpoint. In an API client, create the same request manually rather than importing a request that may contain hidden defaults.

  • Confirm the request reaches the intended environment, not a local, staging, or production host by mistake.
  • Compare the final URL after query parameters are encoded.
  • Record the response status, headers, body, and any request or correlation ID.
  • Repeat the request with a known-valid identifier and a deliberately invalid input to confirm the endpoint is exercising the expected path.

2. Authentication and authorization failures

  • Check that the client sends the expected authentication scheme, commonly through an Authorization header.
  • Verify that the token belongs to the same environment and audience expected by the API.
  • Check expiry, scopes, roles, tenant selection, and resource ownership separately.
  • Look for a missing header caused by a proxy, redirect, client interceptor, or incorrect environment variable.
  • Distinguish identity failure from permission failure: a valid identity can still lack access to an operation or resource.

Never paste live credentials into a public issue, browser screenshot, shell history shared with others, or code sample. Use a redacted token marker when documenting the request.

3. Content type and request-body problems

When a body is rejected, inspect both syntax and semantics. A valid JSON document can still fail because a field has the wrong type or because the endpoint expects a different property name.

  • Set Content-Type: application/json when sending JSON, and ensure the body is actually JSON rather than a language object representation.
  • Use Accept: application/json when requesting a JSON response, but do not confuse it with Content-Type.
  • Check commas, quotes, null handling, date formats, numeric values, arrays, and nested objects.
  • Compare the payload with the endpoint schema, including required fields and whether unknown fields are rejected.
  • Parse structured validation errors instead of displaying only a generic “request failed” message.

For a deeper payload check, validate representative requests against the API’s JSON Schema when one is available. The JSON Schema validation guide covers conditional fields, arrays, and common API validation patterns.

4. Browser-only failures and CORS

If a request succeeds with curl but fails in browser JavaScript, inspect the browser’s Network panel and console. The browser may enforce cross-origin rules that do not apply to command-line clients.

A non-simple cross-origin request can trigger a preflight request using OPTIONS. Check whether the server responds with the expected CORS headers, including an allowed origin, requested method, and requested headers. A preflight response that returns an error, redirects unexpectedly, or omits a required header can prevent the actual request from being sent.

  • Identify the exact page origin: scheme, host, and port all matter.
  • Inspect the preflight request, not only the failed application request.
  • Check whether credentials are being sent and whether the server’s credential policy matches the client request.
  • Do not treat a development proxy as proof that production CORS configuration is correct.
  • Remember that CORS is a browser enforcement mechanism; it does not replace server-side authentication or authorization.

5. Pagination, response parsing, and empty results

  • Confirm the parameter names and whether pagination uses page numbers, offsets, cursors, or links.
  • Check whether the API applies a default limit or maximum page size.
  • Preserve cursor values exactly; encoding or trimming them can invalidate the next request.
  • Inspect the full response envelope before assuming the data is at response.data, response.items, or another familiar path.
  • Handle empty collections as valid results unless the API contract says otherwise.

What to double-check

Before escalating an API issue, compare the working and failing requests line by line.

  1. URL: Is the scheme, host, port, base path, version, resource ID, and query string identical?
  2. Method: Did a client default to GET, or did a redirect change how the request is sent?
  3. Headers: Are authorization, content type, accept, and custom tenant or version headers present and spelled correctly?
  4. Body: Is it valid, complete, correctly encoded, and consistent with the method?
  5. Timing: Did the failure begin after a deployment, configuration change, token rotation, dependency change, or database migration?
  6. Logs: Can the server locate the request using a timestamp, trace ID, or correlation ID?
  7. Retries: Is the client retrying a non-idempotent operation or hiding the first, more useful error?

For slow requests, separate connection time, server processing time, and downstream dependency time where your tooling allows it. If the issue involves a database-backed endpoint, query-plan analysis may help after you have established that the request reaches the correct server route; see the SQL EXPLAIN and query plans guide.

Common mistakes

  • Changing several variables at once: Keep the URL, method, headers, and body stable while testing one hypothesis.
  • Trusting the status code alone: A 200 response can contain an error envelope, partial data, or an unexpected schema.
  • Adding headers blindly: Extra headers can trigger preflight requests or conflict with server expectations.
  • Confusing CORS with server failure: First determine whether the request was sent and whether the server produced a response.
  • Logging secrets: Redact authorization values, cookies, API keys, and sensitive payload fields before sharing diagnostics.
  • Retrying every error: Validation, authentication, and permission errors generally need correction rather than repeated requests.
  • Testing only the happy path: Include missing fields, invalid identifiers, expired credentials, empty results, duplicate submissions, and boundary values.
  • Ignoring client-generated transformations: Serializers, interceptors, base URLs, proxies, and automatic retries can change the request you think you sent.

When to revisit

Return to this checklist whenever an endpoint is introduced, a client library changes, authentication is rotated, a browser or proxy configuration changes, or an API regression appears. It is especially useful before release and after infrastructure, schema, dependency, or deployment changes.

Keep a small, versioned request fixture for important integrations: one known-good request, one validation failure, one unauthorized request, and one empty-result case. Update the fixture when the API contract changes. Periodically verify that your API client still shows preflight requests, response headers, timing, and parsed error bodies in a way the team can inspect.

For the next failure, follow this short sequence:

  1. Save the exact URL, method, headers, redacted body, status, and response.
  2. Reproduce the request with curl or a manually configured API client.
  3. Classify the failure by request target, authentication, validation, browser policy, server route, or downstream service.
  4. Change one variable, repeat the request, and record the result.
  5. Use server logs and a correlation ID to confirm what the server received.
  6. Turn the final diagnosis into a regression test, fixture, monitoring check, or clearer error message.

This approach turns API debugging from guesswork into a repeatable investigation that remains useful as endpoints, tools, and workflows evolve.

Related Topics

#APIs#HTTP#CORS#curl#backend development
U

Unbound Dev Hub

Editorial Developer Resources

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.