cURL to JavaScript
Paste a curl command and get JavaScript code using fetch — or pick any other language.
Paste a curl command above to generate code
How curl maps to JavaScript (fetch)
- →The output uses the Fetch API, built into browsers and Node.js 18+, with await.
- →-H headers go into the headers object and -d into body; -X sets method (curl defaults to POST when there's a body).
- →Calling the API from a browser page? The server must allow your origin with CORS headers — curl never checks CORS, browsers do.
- →response.text() is used so non-JSON replies don't throw; switch to response.json() when the API returns JSON.
Frequently asked
Why does the fetch version fail with a CORS error when curl works?
Browsers enforce CORS and curl doesn't. The API has to return Access-Control-Allow-Origin for your site; otherwise call it from your server instead of the browser.
Does fetch send cookies like curl -b?
The Cookie header from -b is copied, but browsers ignore a manually set Cookie header. In the browser use credentials: "include"; in Node.js the header is sent as written.