Skip to content
TabBench

cURL to Fetch Converter

Paste a curl command, including “Copy as cURL” from DevTools, and get working JavaScript fetch code with async/await or .then(), proper body handling and error checks.

Runs in your browser. Nothing you add is uploaded.

What the cURL to Fetch Converter does

API documentation, Stack Overflow answers and your browser's “Copy as cURL” all speak curl, but your front-end code needs fetch. This converter reads the curl command the way curl itself does (clustered flags like -sSL, $'…' strings, several -d parts, the Windows format) and writes idiomatic fetch code: JSON bodies as JSON.stringify of an object, form data as URLSearchParams, uploads as FormData and credentials as headers. It also tells you what cannot carry over to a browser.

How to convert curl to fetch

  1. Paste the curl command. In Chrome, right-click a request in the Network tab and choose Copy, then Copy as cURL.
  2. Choose async/await or a .then() chain.
  3. Decide whether fetch should mimic curl's redirect behaviour and whether to include the response.ok error check.
  4. Copy the generated code. Read the notes underneath for anything that will behave differently in a browser.
  5. If the request needs credentials or cookies across sites, add credentials: 'include' and make sure the server allows it with CORS.

The cURL to Fetch Converter runs entirely in your browser — nothing you enter is uploaded, stored, or logged.

When to use it

Turning API docs into front-end code

Most API references show curl. Convert the example and adapt it to your app without translating flags by hand.

Reproducing a network request

Copy a request from DevTools as curl, convert it to fetch and replay it from a script or test.

Moving a shell script to Node.js

Node.js 18 and later run fetch natively, so a curl-based script can become a short JavaScript file without dependencies.

Good to know

  • fetch does not reject on HTTP errors such as 404. Check response.ok, as the generated code does.
  • Do not set Content-Type by hand for FormData. The browser adds the boundary itself.
  • Forbidden headers (Cookie, Host, Referer, User-Agent) are ignored in a browser but work in Node.js.
  • Use AbortSignal.timeout(ms) for a timeout, as the generated code does for --max-time.
  • Parse JSON with response.json() only when the server sends JSON; otherwise use response.text().

Guides that use this tool

Frequently asked questions

Does the generated code work in Node.js?

Yes, on Node.js 18 and later, which include fetch. On older versions install a fetch polyfill such as node-fetch.

Why is my Cookie or User-Agent header ignored in the browser?

Browsers do not let scripts set certain headers, including Cookie, Host and Referer, and ignore User-Agent. The tool lists which of your headers are affected. From Node.js or a server all of them work.

Why does fetch behave differently from curl on redirects?

curl only follows redirects when you pass -L. fetch follows them by default. Turn on the option to match curl's behaviour if the difference matters.

Why does my converted request fail in the browser with a CORS error?

curl is not a browser, so it ignores CORS. A cross-origin request from a web page only succeeds if the server allows your site with Access-Control-Allow-Origin. Test the request in a terminal first, then ask the API owner to allow your origin.

What happens to -u user:pass?

Basic authentication is an Authorization header holding the Base64 of user:password. The converter writes that header for you, using btoa, which is available in browsers and Node.js 16 and later.

What about --compressed?

It has no effect in fetch code: browsers and Node.js ask for compressed responses and decode them automatically.