Skip to content
FlipConverto home

cURL to Fetch Converter

Convert curl to JavaScript: paste a cURL command and get fetch() code with the same method, headers, body and authentication — and a list of every option that could not be carried over.

Loading cURL to Fetch Converter…

Runs entirely in your browser. What you enter stays on your device — nothing is sent to a server. Verify it yourself

How do you convert curl to JavaScript fetch?

Map -X to method, each -H to a headers entry, -d or --json to body, -u to an Authorization: Basic header and -F to FormData, then call fetch(url, options). This converter does the mapping and lists any option fetch() has no equivalent for.

Cost
Free, no limits
Upload
None — runs on your device
Sign-up
Not required
Works offline
Yes, once loaded

How to convert curl to JavaScript fetch

  1. Copy the command

    Copy a curl command from API documentation, or from your browser’s Network tab with Copy as cURL.

  2. Paste it

    Paste it into the cURL command box. Line continuations with \ or ^ are fine.

  3. Choose the code style

    fetch() with .then() runs in browsers and Node.js; async/await suits a Node.js 18+ script.

  4. Check the notices

    Anything not converted is listed above the code with the reason. Then copy the code.

Examples

  • curl -u alice:s3cret https://api.example.com/mefetch("https://api.example.com/me", { headers: { "Authorization": "Basic YWxpY2U6czNjcmV0", }, })

    Basic auth is user:password, UTF-8 encoded, then Base64.

  • curl -G -d q=books -d page=2 https://api.example.com/searchfetch("https://api.example.com/search?q=books&page=2")

    -G moves the data into the URL and keeps the GET.

  • curl -k -o out.json https://example.comNotice: -k was not converted: fetch() cannot skip TLS certificate checks.

    Unsupported options are reported, not lost.

Key features of the cURL to Fetch Converter

  • Splits commands like bash/zsh or the Windows command prompt, including \ and ^ line continuations
  • Converts -X, -H, -d, --data-raw, --data-urlencode, --json, -u, -b, -F, -G, -I and -m
  • Adds the Content-Type curl would send, so the server sees the same request
  • Writes JSON bodies as editable JSON.stringify() calls
  • Lists every option it could not convert, and why, instead of dropping it
  • Generates promise-chain or async/await code; nothing is run or sent

What it reads and writes

Command syntax

  • bash and zsh
  • Windows cmd (^ escapes)
  • Copy as cURL from Chrome, Edge and Firefox

curl options

  • -X, -H, -A, -e, -r
  • -d, --data-raw, --data-binary, --data-urlencode, --json
  • -u, --oauth2-bearer, -b
  • -F, --form-string
  • -G, --url-query, -I, -m

Output

  • fetch() with .then()
  • async/await for Node.js 18+

When should you use this?

  • Turning an example request from API documentation into code for a web app or Node.js script.
  • Reproducing a request captured with Copy as cURL in your browser’s Network tab.
  • Checking exactly which headers and body a curl command sends.

Limitations

  • Options without a fetch() equivalent — -k, proxies, -o, cookie jars, client certificates, digest and NTLM auth, retries — are listed, not converted.
  • Local files (-d @file, -F field=@file, --data-urlencode @file) cannot be read; the code has a placeholder or, in the Node.js style for form files, uses fs.openAsBlob.
  • Shell variables such as $TOKEN are not expanded; they stay in the code as written.
  • Only the first URL and the first command are converted; URL globbing with [ ] or { } is requested literally.

Troubleshooting

"a single quote (') is never closed"

Part of the command was not copied, or a value contains an apostrophe inside single quotes. In bash, write it as 'it'\''s' or switch that value to double quotes.

The request fails in the browser but works with curl

Usually CORS: the server must allow your page’s origin. curl ignores CORS, browsers do not. Run the code in Node.js, or ask the API owner to allow your origin.

Common mistakes to avoid

  • Leaving out the word curl at the start. The converter needs it to know the rest is a curl command.
  • Expecting a GET with -d to keep its body. fetch() refuses a body on GET or HEAD; use -G to put the data in the URL.
  • Sharing the generated code without removing the token or password it now contains.

Pro tips

Tips for better results

  • Copying

    Prefer Copy as cURL (bash) when you have the choice

    Prefer Copy as cURL (bash) even on Windows if your browser offers both — the bash quoting is easier to read and edit.

  • Secrets

    Move tokens out of the code before committing it

    Move tokens out of the generated code into an environment variable or a config value before committing it.

  • Errors

    Check response.ok — fetch() does not fail on 404

    Check response.ok in your code: unlike curl -f, fetch() only rejects on network errors, not on 404 or 500.

How the command is read

The command is split into words the way a shell would split it, then read the way curl reads its options. Bash and zsh syntax is supported — single and double quotes, backslash escapes, \ at the end of a line, and the $'…' strings that browsers use in “Copy as cURL (bash)”. So is the Windows command prompt: ^ escapes and ^ line continuations, as in Chrome’s “Copy as cURL (cmd)”. The command is only ever read as text; nothing is executed and no request is sent.

Anything after a pipe, ;, && or a redirect belongs to another command and is ignored, with a note saying so.

What is converted

  • Method and URL — -X, --url, -I (HEAD), and POST when there is a body, as curl does. A URL without a scheme gets http://, again as curl does.
  • Headers — -H, plus -A (User-Agent), -e (Referer), -r (Range) and -b name=value (Cookie).
  • Bodies — -d, --data-raw, --data-binary and --data-urlencode, joined with & and sent as application/x-www-form-urlencoded unless you set a Content-Type; --json with JSON headers; and -F fields as FormData. A JSON body is written as JSON.stringify(…) so it is easy to edit.
  • Authentication — -u user:password becomes an Authorization: Basic header (UTF-8, Base64-encoded) and --oauth2-bearer a Bearer header.
  • Query and timeout — -G moves -d data into the query string; -m becomes AbortSignal.timeout().

What fetch() cannot do

Some curl options have no fetch() equivalent: skipping certificate checks (-k), proxies (-x), saving to a file (-o), cookie jars, client certificates, digest or NTLM authentication and retries. Each one in your command is listed above the code rather than silently dropped. Options that need no code — -L (fetch follows redirects anyway), --compressed, -s, -v — are listed separately.

Browsers also refuse to let a page set some headers, including Cookie, Host, Referer and Origin. The code keeps them, because they work when it runs in Node.js, and the notice says which ones a browser will ignore. Local files that curl would read (-d @file, -F field=@photo.jpg) cannot be read by fetch(): in the async/await style, form files use Node’s fs.openAsBlob (Node.js 20 and later); in the .then() style the line is left as a comment for you to pass a File or Blob.

Sources

Privacy

The cURL to Fetch Converter runs entirely in your browser. What you enter and the result it produces stay on your own device — nothing is sent anywhere, because nothing needs to be.

You can confirm this rather than take our word for it: open your browser’s developer tools, watch the Network tab, and use the tool. No request carries your input. It also keeps working with the connection off.

Details are in the privacy policy.

What next?

Percent-encode a value before adding it to a URL.

Encode query values

cURL to Fetch Converter — questions

How do I convert a curl command to JavaScript?

Paste the whole command, starting with the word curl, into the box. The fetch() code appears below; choose .then() for code that runs in browsers and Node.js, or async/await for a Node.js script.

How do I get a curl command from my browser?

Open the developer tools, go to the Network tab, right-click a request and choose Copy → Copy as cURL. Both the bash and the Windows cmd versions can be pasted here.

Why is my Cookie header not sent from the browser?

Cookie is a forbidden request header: browsers ignore it in fetch() and send their own cookies instead, if credentials allow. The generated code still sends it when run in Node.js.

What happens to -k, -o and --proxy?

They are listed in the notice above the code as not converted, with the reason. fetch() cannot skip certificate checks, write to a file or use a proxy on its own.

Is my token sent anywhere when I paste the command?

No. The command is read as text in your browser and the code is generated there; no request is made. Remember the generated code contains any token that was in the command.

Part of Developer Tools · Browse every tool