Tools Guides
Developer Free No signup

cURL to Fetch Converter

Convert cURL commands into JavaScript fetch(), Axios, or Python requests code.

Loading tool…

About this tool

Paste any cURL command and instantly get the equivalent code in three formats: JavaScript fetch() with async/await, Axios, and Python requests. The converter handles all common cURL flags: -X (method), -H (headers), -d / --data / --data-binary (request body), -u (Basic Auth), --compressed (Accept-Encoding), -k (skip TLS verify), and -L (follow redirects). Great for translating API documentation examples or debugging HTTP calls across languages.

How to use

  1. 1 Paste your cURL command into the input box.
  2. 2 The equivalent fetch(), Axios, and Python requests code appear instantly.
  3. 3 Click the Copy button next to the output you want.
  4. 4 Paste the code into your project.

What a cURL command actually contains

A curl command is a compact description of an HTTP request written for the command line. Every flag maps to one part of that request: the bare argument is the URL, -X sets the method, each -H adds a header, -d attaches a request body, and -u supplies HTTP Basic credentials. This converter reads that structure and re-expresses the same request in three runtime libraries — the browser's native fetch(), the Axios client, and Python's requests — so you can lift an API call straight out of documentation or a colleague's terminal and drop it into real code.

The tool tokenizes the command much like a shell would: it respects single and double quotes, so a JSON body wrapped in '{"name":"Alice"}' stays a single argument, and it collapses backslash line-continuations, so multi-line commands paste cleanly. Everything runs in your browser — nothing you paste is sent anywhere.

A worked example

Paste this command:

  • curl -X POST https://api.example.com/users -H 'Content-Type: application/json' -d '{"name":"Alice"}'

The parser records the method POST, the URL, one header, and a body. It then emits the fetch() equivalent: fetch("https://api.example.com/users", { "method": "POST", "headers": { "Content-Type": "application/json" }, "body": "{\"name\":\"Alice\"}" }), followed by const data = await response.json();. The Axios version moves the body into a data field; the Python version produces requests.post(...) with a headers= dict and a data= argument. Notice one detail the converter handles for you: if you supply a body with -d but no explicit -X, cURL itself would default to POST, so the tool does too. That single rule trips up a lot of hand-written conversions.

How specific flags are translated

  • Authentication (-u user:pass). For fetch() the credentials are Base64-encoded into an Authorization: Basic header, because the Fetch API has no separate auth option. Axios and requests instead receive a structured auth object, matching how those libraries expect credentials.
  • Insecure TLS (-k/--insecure). The tool adds a comment rather than silently dropping it. Browsers cannot disable certificate validation from JavaScript, so the fetch() output flags this as not applicable; the Python output emits verify=False, the genuine equivalent.
  • Following redirects (-L). fetch() follows redirects by default, so the tool notes that. In Python, redirects are followed by default too, so when -L is absent the converter adds allow_redirects=False to preserve cURL's stricter behavior.
  • Compression (--compressed). Recognized and parsed, since modern HTTP clients negotiate gzip automatically.

Common use cases

The most frequent reason people reach for this tool is that API providers document their endpoints as cURL one-liners. Converting one to fetch() lets you try the request in a browser console or a frontend component; converting to requests drops it into a Python script or a Jupyter notebook. It is also handy when a teammate shares a working call captured from their terminal and you need it in the language your project uses. Browser DevTools can already "Copy as cURL" from the Network tab, so a round trip — copy a real request as cURL, paste it here — turns any observed network call into reusable code.

Practical tips

  • Keep your quoting intact. Wrap JSON bodies in single quotes so inner double quotes survive. If you unquote them, the shell-style tokenizer may split your body at spaces.
  • Set -X explicitly for PUT, PATCH, and DELETE. Without it, only a body triggers the automatic switch to POST; everything else stays GET.
  • Treat the output as a starting point for streams and files. The generated code calls response.json(), which assumes a JSON response. If your endpoint returns text, HTML, or a binary blob, swap in response.text() or response.blob().

Common mistakes

  • Pasting without the word curl. The parser requires the command to begin with curl and to contain a URL; a bare URL alone will not convert.
  • Expecting cookies and proxies to carry over. The converter focuses on method, URL, headers, body, and auth. Niche flags such as --cookie, -x (proxy), and client certificates are skipped, not faithfully reproduced — add those by hand if you rely on them.
  • Assuming fetch() rejects on HTTP errors. Unlike requests, fetch() only rejects on network failure, not on a 404 or 500. Check response.ok before parsing if you need that behavior.

Frequently Asked Questions

{# Alpine.js — self-hosted. (The previous jsdelivr CDN tag had a stale SRI integrity hash, so the browser refused to run it and window.Alpine was never defined — silently breaking every FAQ accordion and Alpine tool.) #}