cURL to fetch is a free converter that turns cURL commands into JavaScript code using the built-infetch API. Headers, JSON bodies, form data, cookies and basic authentication are all carried over. The command is converted in your browser, so tokens and passwords in it stay private.
How to convert cURL to fetch
- Paste a cURL command into the left box.
- The JavaScript appears on the right. Switch to Python or axios with the tabs if you need another language.
- Copy the code into your project. It uses
await, so run it inside an async function or a module.
Getting a cURL command
- From your browser: open developer tools (F12), go to the Network tab, right-click a request and choose Copy → Copy as cURL. On Windows, pick the “bash” version.
- From API documentation: most APIs (Stripe, GitHub, OpenAI and others) show examples as cURL commands.
- From Postman or Insomnia: use the code snippet or “Copy as cURL” option.
What the generated code does
- JSON bodies become
JSON.stringify(…)with a readable object, so they are easy to edit. - -u user:pass becomes an
Authorization: Basicheader built withbtoa. - -F form fields become a
FormDataobject; file fields use a file input. - No -L adds
redirect: 'manual', because fetch follows redirects and curl doesn’t by default.
Running it in a browser vs Node.js
fetch is built into browsers and into Node.js 18 and later, so the same code works in both. In a browser, the API must allow your site through CORS, and headers such as Cookie andUser-Agent can’t be set by scripts. For server-side code you may prefercURL to axios.
Frequently asked questions
Is it safe to paste commands with tokens or passwords?
Yes. The command is converted inside your browser and never sent anywhere. Still, remember to remove real secrets before sharing the generated code with others.
Which cURL options are supported?
The ones used for API requests: -X, -H, -d and its variants, --json, -F (forms and file uploads), -u (basic auth), -b (cookies), -A, -e, -G, -I, -L, -k and --compressed. Output options such as -o, -s and -v are ignored, and anything else is listed as a warning.
Why does the code include redirect: 'manual'?
Without -L, curl doesn’t follow redirects, but fetch does by default. The option keeps the behaviour the same; delete it if you do want redirects followed.
Will this work in the browser?
Yes, if the API allows it. Browsers enforce CORS: the API must allow requests from your site. Some headers, such as Cookie and User-Agent, can’t be set from browser JavaScript and are ignored there, but they work in Node.js.
Last updated