cURL to Fetch Converter
Convert cURL commands into JavaScript fetch(), Axios, or Python requests code.
이 도구에 대해
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.
사용 방법
- 1 Paste your cURL command into the input box.
- 2 The equivalent fetch(), Axios, and Python requests code appear instantly.
- 3 Click the Copy button next to the output you want.
- 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). Forfetch()the credentials are Base64-encoded into anAuthorization: Basicheader, because the Fetch API has no separate auth option. Axios andrequestsinstead 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 thefetch()output flags this as not applicable; the Python output emitsverify=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-Lis absent the converter addsallow_redirects=Falseto 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
-Xexplicitly 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 inresponse.text()orresponse.blob().
Common mistakes
- Pasting without the word
curl. The parser requires the command to begin withcurland 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. Unlikerequests,fetch()only rejects on network failure, not on a 404 or 500. Checkresponse.okbefore parsing if you need that behavior.