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

  1. Paste the curl command. Long commands can span several lines, with a backslash at the end of each line, as shells expect.
  2. Pick the language.
  3. Copy the code, or download it as a file (request.mjs for JavaScript, request.py for 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: -d and -F make a POST, -I a HEAD and -T a PUT.
  • The URL, with any query that -G or --url-query adds.
  • Headers from -H, the user agent from -A, the referrer from -e, and cookies from -b, which become a cookies dict in Python.
  • Basic authentication from -u or 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 --json or a JSON Content-Type becomes an object or dict, form data from -d becomes URLSearchParams or a dict, and multipart forms from -F become FormData or a files dict, with file uploads included.
  • The timeout from --max-time (and --connect-timeout in Python), -k to 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.json or -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/ becomes requests.get("https://example.com/") in Python.
  • curl -u ada:secret https://api.example.com/me becomes auth=("ada", "secret") in Python and an auth option in Axios.
  • curl --json '{"item": "sourdough loaf"}' https://api.example.com/orders becomes json={"item": "sourdough loaf"} in Python and JSON.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