cURL to fetch / axios Converter
Paste a cURL command — get ready-to-use JS fetch or axios code with headers, body, method, and basic auth handled.
const response = await fetch("https://api.example.com/v1/users", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer abc123",
},
body: "{\"name\":\"Alice\",\"role\":\"admin\"}",
});
const data = await response.json();How to use
- Paste the cURL command in the input box.
- Pick
fetchoraxiosto match your target. - Copy the resulting code into your file.
About this tool
ShowHide
Paste a cURL command and get ready-to-run JavaScript — either fetch, the platform built-in, or axios. The common flags are understood, including method, headers, the various data forms, JSON, basic auth, user agent and cookies, and backslash continuations and quoted strings are handled so a browser's Copy as cURL output pastes straight in. Two translations are worth knowing about. Basic auth becomes an Authorization header holding the Base64 of user:pass, because fetch has no credentials argument of its own. And a cookie flag becomes a Cookie header, which is fine in Node but which a browser will refuse to set from JavaScript — cookies are the browser's to manage, so use credentials: 'include' instead when the call runs in a page.
Frequently asked questions
Where can I get a cURL command to paste?
Chrome / Firefox / Safari DevTools → Network tab → right-click any request → Copy → Copy as cURL. Postman and Insomnia have a similar export.
Does it understand --json?
Yes. --json shorthand sets the body and adds the Content-Type: application/json and Accept: application/json headers if you didn't set them already.
What about -L, -s, -v?
Flags that don't change the request payload are ignored — fetch and axios already follow redirects by default, and verbose output is a CLI-only concern.
Why does axios output put the body as data:?
axios uses data for request bodies, and if the body parses as valid JSON the converter emits it as a JS object literal — but only when the Content-Type is JSON or unset. With a form or other Content-Type, or a body that doesn't parse, it stays a string, because axios would URL-encode an object sent as a form and change the bytes curl sends.
How are repeated -d options handled?
They are merged into one body separated by &, which is what curl itself does: -d a=1 -d b=2 sends a=1&b=2, not two separate bodies and not a=1b=2. The same applies across the data flags, so mixing -d and --data-raw in one command still produces a single joined body. --data-urlencode is percent-encoded the way curl does it: in name=value only the value is encoded, so q=hello world becomes q=hello%20world. Data sent with the -d family also gets curl's Content-Type: application/x-www-form-urlencoded unless you set one, and with -G the joined data goes into the query string of a GET instead of a body.
Does -u work with a non-ASCII password?
Yes, and it is encoded as UTF-8 before base64 as RFC 7617 requires. This is worth stating because the naive approach — passing the string straight to the browser's btoa — reads it as latin-1 instead: an accented password comes out as different bytes that the server will reject, and anything above U+00FF, such as Korean or Japanese, makes btoa throw outright. Check the generated Authorization header if a login works in curl but not in the converted code.
Related tools
.gitattributes Tester
Paste a .gitattributes and a list of paths to see every attribute git ends up setting on each path, and which line — or which macro — set it.
Developer
String Escape Converter
Escape a string for 10 contexts at once — JavaScript, JSON, HTML entities, URL, SQL, regex, Bash (single/double quote), C string, Unicode \u escapes.
Developer
Unicode Escape Converter
Encode text to \uXXXX, U+XXXX or HTML entities — and decode any of those back to text. Handles emoji and astral characters.
Developer
Regex Tester
Test JavaScript regular expressions live with highlighted matches and replace preview.
Developer
Base64 to Hex Converter (and back)
Convert a Base64 string to hexadecimal bytes and hex back to Base64, with URL-safe support, in your browser.
Developer
Docker Run to Compose Converter
Turn a docker run command into a docker-compose.yml — ports, volumes, environment and limits mapped for you.
Developer