CORS error in JavaScript

curl doesn't enforce CORS. Fetch and Axios do. A working curl doesn't mean a working browser call. Paste your curl command to see what JavaScript (fetch) would send and compare against the working request.

Quick answer

To convert a cURL command to JavaScript, paste it into the Toolpaper workbench below. It parses the command in your browser and emits idiomatic JavaScript code — headers, query string, request body, authentication (Bearer, Basic, API key), and cookies are all wired up automatically. No data is uploaded; conversion is fully client-side.

Prefer a different target? See the full cURL to JavaScript reference, or jump to the same guide in Node.js, Python, or Go.

InputcURL command
1 secret
MethodGET·Headers1·Body—· Chars 73
OutputJavaScript · fetch(browser/Node)
const response = await fetch("https://api.example.com/me", {
  method: "GET",
  headers: {
    "Authorization": "Bearer YOUR_TOKEN"
  },
  redirect: "manual"
});
const data = await response.json();
Inspect

Example

A representative curl command for this scenario. Paste your own above to convert an exact match.

curl input
curl https://api.example.com/me \
  -H "Authorization: Bearer YOUR_TOKEN"

Implementation notes

  • Move the call server-side, or ask the API to add your origin to Access-Control-Allow-Origin. The In-browser Runner surfaces CORS blockers explicitly.
  • Use the Explain panel to enumerate exactly which headers, cookies, and TLS flags the curl request carries.
  • The In-browser Runner is a fast way to confirm whether the failure reproduces from the browser or only from the server.

Common mistakes

  • Comparing curl and JavaScript without capturing both actual wire requests — mitmproxy or Charles pays off here.
  • Assuming a working curl means the API is happy — client differences (redirect handling, keep-alive, HTTP/2) surface as edge cases.
  • Silencing warnings instead of fixing them — every JavaScript client has a way to log the outgoing request; turn it on.

Common questions

Why does curl work but JavaScript fail?
Usually a header curl adds by default is missing in JavaScript, or vice versa. Paste the curl above to see a normalized breakdown.
Is my request sent to Toolpaper?
No. Parsing and diffing run in your browser.

More guides in JavaScript

JavaScript hub →

The same guide in other languages

All guides →

Full JavaScript reference on the cURL to JavaScript hub, or open the main converter for all 18 targets.