Free tool

cURL to code converter

Paste the curl you copied from the docs or the Network tab and get ready-to-use code in eight languages, without leaving secrets in the code.

curl command

Supports bash (quotes, $'…', trailing \), Windows cmd (^) and PowerShell (`), like the ones browsers copy from the Network tab.

Node 20+ o navegador / Node 20+ or browser
const response = await fetch("https://api.example.com/v1/orders", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.API_TOKEN,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "product": "macm-pro",
    "quantity": 2,
    "gift": false
  }),
});

console.log(response.status);
console.log(await response.text());

Detected request

POST https://api.example.com/v1/orders

  • Authorization: Bearer $API_TOKEN
  • Content-Type: application/json

Body · 48 bytes

.env

API_TOKEN=sk_live_51Hx
Limits
  • Method, URL, headers, body, multipart forms, basic auth, cookies, timeout, -k and -L are translated. Options such as client certificates, --resolve or retries are ignored with a warning.
  • Java skips headers HttpClient forbids (Host, Content-Length, Connection, Expect, Upgrade).
  • JavaScript and Python output is validated with their compilers and Java by compiling with javac; Go, PHP, Rust and C# follow each client's official documentation.
  • The command is neither executed nor sent: with real tokens, conversion happens only in your browser.

Built by

Miguel Ángel Colorado Marin (MACM)

Full-Stack Developer · Guadalajara, España

I develop web apps, digital tools and full projects — from design to deployment.

Contact me

Almost every API doc ships curl examples, and browsers let you copy any request with "Copy as cURL". Turning it into code by hand means fighting quotes, escapes and obscure options. This converter parses the command the way a shell would, including the cmd format with ^ that Chrome uses on Windows, and generates idiomatic code for eight HTTP clients. It also moves tokens, API keys, cookies and passwords to environment variables: pasting a real request with your session and pushing the result to a repository is one of the most common ways credentials leak.

Features

  • Eight outputs: JavaScript fetch, Axios, Python requests, Go net/http, PHP cURL, Rust reqwest, Java HttpClient and C# HttpClient
  • Understands single and double quotes, $'…', \ line breaks, Windows cmd with ^ and PowerShell with `
  • Translates -X, -H, -d, --data-raw, --data-urlencode, --json, -F with files, -u, -b, -A, -e, -G, -I, -T, -k, -L and --max-time
  • Moves Authorization, API keys, cookies, passwords and URL tokens to environment variables and generates the .env
  • JSON bodies as native objects (dict in Python, object in JS) or as text
  • Summary of the detected request and warnings for options that cannot be translated
  • Option to reproduce curl's exact redirect policy
  • Output validated with node --check, py_compile and javac, with string escaping tested against each compiler

How do I convert a curl command to code?

  1. 1

    Copy the curl

    Copy it from the docs or from developer tools: Network tab, right click, Copy as cURL.

  2. 2

    Paste it

    Paste the full command, line breaks included. Bash, cmd or PowerShell is detected automatically.

  3. 3

    Choose language and options

    Select the HTTP client, whether you want JSON as an object and whether to move secrets to environment variables.

  4. 4

    Copy the code and the .env

    Copy the generated code and, if there are secrets, the .env block with their values for your local file.

Frequently asked questions

How do I copy a request as curl from the browser?

Open developer tools (F12), go to the Network tab, reload the page, right-click the request and choose Copy, Copy as cURL. On Windows Chrome offers cmd and bash versions; this tool understands both.

Why move secrets to environment variables?

A request copied from the browser usually includes your session cookie or a Bearer token. If that code ends up in a repository, anyone with access can use your account. With environment variables the code stays clean and the value lives in a .env file that is not committed.

What happens with -d and the HTTP method?

Just like curl: -d switches the method to POST and adds Content-Type application/x-www-form-urlencoded unless you set another; several -d are joined with &. With -G the data goes into the query string and the method stays GET.

Are redirects followed?

curl does not follow redirects unless you pass -L, while most HTTP clients do by default. By default the code follows each client's convention; enable "Exact curl redirects" to reproduce the original behaviour.

Which options cannot be converted?

Those that depend on curl itself or the system, such as client certificates, --resolve, retries, rate limits or cookie files. They are ignored and the tool warns you so you can configure them in your client.

Is the command executed or sent?

No. Conversion is a text analysis in your browser: the request is never made and tokens never leave your device.

Related tools

Embed cURL to Code on your site

Add cURL to Code to any web page with a simple iframe. Free, with attribution to miguelacm.es.

<iframe
  src="https://miguelacm.es/embed/curl-to-code"
  width="100%"
  height="700"
  frameborder="0"
  title="cURL to Code — miguelacm.es"
></iframe>
View embed in new tab →