cURL to Fetch Converter
Convert a cURL command into JavaScript fetch() code, with headers, JSON bodies, basic auth and form data handled.
How it works
Paste a cURL command (the kind you get from a browser's "Copy as cURL" menu item) and this
converter tokenises it with a small POSIX-style shell splitter that understands single
quotes, double quotes, backslash escapes and line continuations (both \ and the
Windows ^ form). It then maps the flags it recognises onto a
WHATWG Fetch
call: -X/--request becomes method,
-H/--header becomes headers,
-d/--data/--data-raw/--data-binary and
--data-urlencode become body, -F/--form
becomes a FormData object, -u/--user becomes an
Authorization: Basic header encoded per
RFC 7617 (base64 of user:password), and -G/--get
moves the data into the query string using URLSearchParams. -I maps to
method: 'HEAD' and --json sets both Content-Type and
Accept to application/json.
This is a best-effort translator, not a complete implementation of curl's command line.
It handles the flags listed above plus the common transfer switches; anything it does not
recognise is reported in the "Translation notes" box under the output rather than being
dropped silently. Some curl options simply have no equivalent in the browser
(-k/--insecure, --proxy, --cert,
-o, --resolve), and a few are handled by the browser for you
(--compressed, -L, and hop-by-hop or forbidden headers such as
Host, Content-Length, Connection and
User-Agent, which fetch refuses to let you set). Always read the
notes and give the generated code a quick review before you ship it.
Everything runs in JavaScript on your device. The command you paste is never uploaded, no request is ever sent, and the generated code is not executed โ so it is safe to paste a command that carries a session cookie or a bearer token while you are debugging.
Frequently asked questions
How do I convert a cURL command to fetch()?
Paste the command into the input box and the fetch() code appears instantly below it. The converter maps -X to method, -H to headers, -d and --data-raw to body, -F to FormData and -u to an Authorization: Basic header encoded per RFC 7617. Pick async/await, a .then() chain or just the options object, then use Copy JavaScript or Download .js.
Is it safe to paste a cURL command that contains a session cookie or API token?
Yes. The command is parsed by JavaScript running on your device, nothing is uploaded to a server, no request is ever sent and the generated code is never executed. That makes it safe to paste a Copy as cURL command straight out of DevTools while you are debugging a signed-in request.
Why did the converter drop my Cookie, Host or User-Agent header?
The Fetch Standard lists those as forbidden header names, so a page is not allowed to set them and the browser fills them in itself. Rather than emitting code that would silently fail, the tool removes them and explains what happened in the Translation notes panel, swapping a Cookie header for credentials: "include" where that is the closest equivalent.