Skip to content
AZ Tools

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.

Target:
JS code
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

  1. Paste the cURL command in the input box.
  2. Pick fetch or axios to match your target.
  3. Copy the resulting code into your file.

About this tool

Show

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