Skip to content

cURL to JavaScript fetch

Converts cURL commands into JavaScript fetch code, including headers, JSON bodies, forms and auth.

Your command stays on this device

This tool runs entirely inside your web browser. Your command is processed on your own device and is never sent to our servers. How this works

JavaScript fetch

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

  1. Paste a cURL command into the left box.
  2. The JavaScript appears on the right. Switch to Python or axios with the tabs if you need another language.
  3. Copy the code into your project. It uses await, so run it inside an async function or a module.

Getting a cURL command

What the generated code does

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

Missing a feature, or need a tool we don’t have? Suggest it.