1001Ferramentas
🔁Converters

cURL to fetch()

Paste a cURL command and generate the JavaScript fetch() equivalent. Supports -X, -H, -d, --data-raw, querystring and cookies. Everything in your browser.

Convert cURL to JavaScript fetch()

API documentation almost always gives the examples in cURL, except on the front end what you want is the fetch() equivalent. Rewriting it by hand, translating header by header and every parameter, is tedious and a single slip away from a mistake. This converter does that translation on its own.

Paste the cURL command and get the matching fetch(). It handles the most common elements: the method (-X), the headers (-H), the request body (-d, --data-raw), the query string and cookies. Within seconds the code is ready to drop into your JavaScript project.

The conversion runs entirely in the browser, so the command never leaves your device. You can convert requests carrying tokens or sensitive data without worrying.

Frequently asked questions

Which cURL flags does the converter actually understand?
It reads the method (-X or --request), the headers (-H or --header), the body (-d, --data, --data-raw or --data-binary) and the first word starting with http, which it treats as the URL. Everything else drops silently: -b and --cookie, -u for basic auth, -F for multipart, --data-urlencode, -L and --compressed all vanish without warning. A cookie passed as a header, in the -H 'Cookie: a=1' shape, survives precisely because it counts as a header.
Why did the method come out as POST when I never wrote -X POST?
The presence of a body switches the default. The converter starts at GET and, on finding -d or any --data variant, moves to POST, which mirrors what cURL itself does at the command line. For a different verb, write -X and the explicit value wins, whether it sits before or after the body. The body lands in the fetch() call as a string, unparsed, so a JSON payload stays quoted inside the body field.
Does the generated code run exactly as it comes out?
It runs, though read it before pasting. The output always ends in .then(r => r.json()).then(console.log), which breaks on a response that isn't JSON, and there's no error handling or r.ok check. The tool never fires the request either: it only rewrites text, inside the browser, with the command reaching no server at all. That's why pasting a cURL carrying an authorisation token exposes nothing.

Related Tools