Developer Tools

cURL to Fetch Converter

Convert a curl command into JavaScript fetch() code, with headers, JSON bodies, form data and basic auth handled.

Tip: in browser DevTools, right-click a request in the Network tab and choose Copy › Copy as cURL (bash).

POSThttps://api.example.com/v1/orders?status=open
JavaScript (fetch)
const response = await fetch("https://api.example.com/v1/orders?status=open", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_TOKEN",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "sku": "MUG-01",
    "qty": 2
  }),
});

if (!response.ok) {
  throw new Error(`HTTP ${response.status}`);
}
const data = await response.json();
console.log(data);

About this tool

API documentation usually shows requests as curl commands, and browser DevTools can copy any network request as curl. Turning that into JavaScript by hand means rewriting headers, quoting the body and remembering which flag means what. Paste the command here and get ready-to-run fetch() code instead.

The converter understands shell quoting and line continuations, headers, the different -d variants, --json, -G, form uploads with -F, basic auth with -u, cookies, user agents and referrers. Options that fetch cannot reproduce, such as -k or a proxy, are listed with an explanation instead of being silently dropped. Nothing you paste, including tokens, leaves your browser.

How to use cURL to Fetch Converter

  1. Paste a curl command. Multi-line commands with trailing backslashes work as they are.
  2. Choose async/await or .then() style.
  3. Choose whether to parse the response as JSON and whether to leave out headers the browser controls itself.
  4. Read the notes below the request summary, then copy the generated code.

Examples

A JSON POST

Input
curl -X POST https://api.example.com/v1/items -H 'Content-Type: application/json' -d '{"name":"mug","qty":2}'
Result
fetch(…, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ "name": "mug", "qty": 2 }) })

JSON bodies are pretty-printed inside JSON.stringify so they are easy to edit.

Query parameters with -G

Input
curl -G https://api.example.com/search --data-urlencode 'q=blue mugs'
Result
fetch("https://api.example.com/search?q=blue%20mugs")

Basic auth

Input
curl -u admin:s3cret -X DELETE https://api.example.com/items/42
Result
method: "DELETE", headers: { "Authorization": "Basic YWRtaW46czNjcmV0" }

Why a request that works in curl can fail in the browser

curl talks to the server directly. fetch() in a web page runs under the browser’s security rules: a request to another origin succeeds only if the server allows it with CORS headers, cookies are sent only with credentials: "include", and certain headers, such as Cookie, Referer, Host, Content-Length and everything starting with Sec-, are set by the browser and silently ignored if you add them. The same code works without these limits in Node.js 18 or later, Deno and Bun, which all have fetch built in.

How curl options are translated

  • -d, --data, --data-raw and --data-binary become the body; several are joined with &, and Content-Type defaults to application/x-www-form-urlencoded, as in curl.
  • --json sets both Content-Type and Accept to application/json.
  • -G moves the data into the URL query string and keeps the method GET.
  • -F builds a FormData object; file fields (@file) are marked so you can pass your own File or Blob.
  • -u becomes an Authorization: Basic header, and -A, -e and -b become User-Agent, Referer and Cookie headers.
  • Without -X, the method is POST when there is a body or form, and GET otherwise.

Frequently asked questions

Everything you need to know about this tool and data security.

Is my command sent anywhere?

No. Parsing and code generation happen in your browser, so API keys and tokens in the command stay on your device.

Does it support Windows cmd or PowerShell syntax?

It reads POSIX shell (bash, zsh) quoting. In Chrome or Edge DevTools, choose Copy as cURL (bash) rather than the cmd or PowerShell variant.

How do I add a timeout?

Pass signal: AbortSignal.timeout(5000) in the fetch options to abort after 5 seconds. If the curl command used -m or --max-time, the tool tells you which value to use.

Why are some headers missing from the output?

With “Leave out browser-controlled headers” on, headers that fetch cannot set in a browser are removed and listed in a note. Turn it off to keep them, for example for Node.js.

Does fetch follow redirects like curl -L?

Yes, fetch follows redirects by default, so -L needs no translation. Use redirect: "manual" if you need the opposite.

Is my data safe when using this tool?

Yes, 100% safe. This tool operates entirely inside your web browser using client-side JavaScript and WebAssembly. Your data never touches any external server.