cURL to Code Converter
Convert a curl command into JavaScript fetch, Axios or Python Requests code with the same method, headers, cookies, authentication and body. Runs in your browser.
Input
Output
Readme
What does it do?
The cURL to Code Converter turns a curl command into code that sends the same HTTP request from your own program. It writes three kinds of code:
- JavaScript (fetch): the fetch API built into browsers, Deno, Bun and Node.js.
- Node.js (Axios): the popular Axios library, with Node.js modules for files and TLS settings.
- Python (Requests): the Requests library.
A common way to get a command is your browser's developer tools: in the Network panel, right-click a request and choose Copy as cURL. API documentation also often shows its examples as curl commands.
How to use it
- Paste the curl command. Long commands can span several lines, with a backslash at the end of each line, as shells expect.
- Pick the language.
- Copy the code, or download it as a file (
request.mjsfor JavaScript,request.pyfor Python).
The code updates as you type. When the command has a mistake that would stop curl itself, such as an unclosed quote or an unknown option, the tool points to it instead.
What gets converted
- The method, including the ones curl picks itself:
-dand-Fmake a POST,-Ia HEAD and-Ta PUT. - The URL, with any query that
-Gor--url-queryadds. - Headers from
-H, the user agent from-A, the referrer from-e, and cookies from-b, which become acookiesdict in Python. - Basic authentication from
-uor from the URL, using each library's own way of sending it, and Bearer tokens from--oauth2-bearer. Python also gets Digest authentication. - Bodies: JSON from
--jsonor a JSON Content-Type becomes an object or dict, form data from-dbecomesURLSearchParamsor a dict, and multipart forms from-FbecomeFormDataor afilesdict, with file uploads included. - The timeout from
--max-time(and--connect-timeoutin Python),-kto skip TLS checks, CA and client certificates, and a proxy from-x.
Headers that curl adds itself, such as its own User-Agent, Accept: */* and Content-Length, are left out, as the libraries send their own. Options that change only how curl shows the response, like -s or -v, are left out too.
When something can't be converted
Some things have no equivalent in a library or language. Those become comments at the top of the code, so nothing is dropped silently:
- Options with no counterpart, such as
--retry, are listed as "Not converted". - fetch can't skip TLS checks, use a proxy or set a connect timeout, and browsers don't let scripts set the Cookie header, although Node.js does.
- Files curl reads, like
-d @data.jsonor-F photo=@cat.jpg, are read from disk in Node.js and Python. In browser JavaScript they appear as a placeholder for you to replace, for example with a file from an<input type="file">. - When a command sends several requests, the code is for the first one.
Examples
curl https://example.com/becomesrequests.get("https://example.com/")in Python.curl -u ada:secret https://api.example.com/mebecomesauth=("ada", "secret")in Python and anauthoption in Axios.curl --json '{"item": "sourdough loaf"}' https://api.example.com/ordersbecomesjson={"item": "sourdough loaf"}in Python andJSON.stringify({ item: "sourdough loaf" })with fetch.
How it works
The command is read the way a shell and curl read it, with quotes, escapes and line continuations, by the same parser as the site's cURL Command Validator. The request curl would send is then written out as code. Everything happens in your browser, so commands with tokens or passwords never leave your device.
Features
- JavaScript fetch, Node.js Axios and Python Requests
- Headers, cookies, Basic and Bearer authentication
- JSON, form, multipart and file bodies
- Timeouts, TLS options, certificates and proxies
- Comments for anything that can't be converted
- Clear messages for mistakes in the command
- Copy or download the code
- Runs in your browser