Converter tool

cURL to Code Converter

Paste a curl command, including Chrome's Copy as cURL in bash or cmd form, and get the same request as JavaScript fetch, Node axios, Python requests, Go, PHP or Rust code, with tokens moved into environment variables.

Paste Copy as cURL from the browser's network panel, or a command from API documentation.0 / 1,000,000 characters

The command is read by script in this tab and nothing is sent anywhere: not to this site, and not to the URL in the command. Files named with @ are never opened; the code reads them when you run it. This tool keeps nothing in localStorage, sessionStorage or IndexedDB.

Preview

Output Preview

Paste a curl command and the code appears here as you type.

cURL to Code Converter

Operator: Abdulla Al Fahad. How tools are built and checked

Copy as cURL is the quickest way to capture a request exactly as the browser sent it: every header, the session cookie, the body byte for byte. Turning that block of -H flags into code is the slow part. The shell quoting has to be undone by hand, the JSON body rebuilt in the target language, and someone has to remember not to commit the cookie that was pasted along with it.

This converter reads the command the way a shell would, in bash or Windows cmd form, and writes the same request for six clients: JavaScript fetch, Node axios, Python requests, Go's net/http, PHP's curl extension and Rust's reqwest. Bearer tokens, cookies, API keys and -u passwords are replaced with environment variables by default. When a library cannot do what a curl flag asks, such as fetch skipping certificate checks, the code says so in a comment instead of dropping the flag silently.

Key features

  • Six outputs: fetch, axios, Python requests, Go net/http, PHP cURL, and Rust reqwest with the async (tokio) or blocking client
  • bash and Windows cmd quoting, detected from the text, including Chrome's ^"...^" cmd format
  • Headers, -d, --data-raw, --data-binary, --data-urlencode and --json bodies, -F uploads, -u, -b, -G, -I, -L, -k, -x, -m and --connect-timeout
  • JSON bodies rebuilt as objects (a dict in Python, json! in Rust, a PHP array) when the Content-Type is JSON
  • Secrets moved into environment variables, on by default, with the list of variables the code expects
  • A comment in the code for each curl option the target library cannot match
  • A note for every flag that was ignored, with the reason

How bash and cmd commands are parsed

The bash reader covers what browsers and API documentation put in commands: single quotes, double quotes with \" \\ \$ and \` escapes, $'...' strings with \n, \t, \xHH, \uXXXX and the other ANSI-C escapes, backslash line continuations (spaces left after the backslash are tolerated), a leading "$ " prompt and the curl.exe program name. $NAME and ${NAME} become environment-variable reads in the code. Text after a pipe, semicolon or redirect, such as | jq ., is ignored, and an unquoted & inside a URL is kept as part of it, with a note, because that is what the author almost always meant.

The cmd reader removes ^ escapes and ^ line continuations the way cmd.exe does, splits the arguments with the Microsoft C runtime rules for quotes and backslashes, and turns %NAME% into an environment-variable read. The syntax is guessed from the text, caret continuations and ^" against backslash continuations and single quotes, and can be set by hand in the Shell syntax menu.

Commands up to 1,000,000 characters are read. A Copy as PowerShell command (Invoke-WebRequest) is refused with a message, because its syntax is different; copy the request as cURL instead.

How it works

The command is first split into words. Quotes and escapes are resolved once, as the shell resolves them before curl starts, so the strings in the code are the values curl would have received.

The words are then read as curl options. Short flags can be grouped (-sSL) or carry their value (-XPOST, -d@body.json). Long options must be spelled out; --name=value is accepted with a note, although curl itself rejects that form. Options that take a value but have no counterpart in the code, such as --retry 3 or --cacert ca.pem, are skipped together with their value, so the value is never mistaken for the URL.

The method follows curl's rules: -X wins, otherwise -I gives HEAD, -G gives GET, -T gives PUT, and any data or form makes it POST. Several -d pieces are joined with &, --json pieces with nothing between them. When data is sent without a Content-Type, the code sets application/x-www-form-urlencoded, because curl adds that header by itself and fetch or Go would otherwise send something different. Content-Length is always dropped, since every library counts the body it actually sends.

Each generator then writes its language. A body becomes a native object only when the Content-Type is application/json, another +json type or text/json, and the text parses as JSON; anything else stays a string, unchanged.

Common use cases

  • Replaying a failing request from a bug report in a Python script, with the customer's session cookie replaced by a variable
  • Turning the curl example in an API's documentation into the first working call of a Go or Rust integration
  • Writing an export job from the request a web app makes when you press its Download button
  • Moving a request saved in Postman or Insomnia, both of which export cURL, into application code
  • Checking what a long command really sends: the method, URL, number of headers and body type are listed above the code

How to use this tool

  1. In the browser's developer tools, open the Network panel, right-click the request and choose Copy as cURL (bash). On Windows, Copy as cURL (cmd) works as well.
  2. Paste the command into the box. The code appears as you type, and a quoting mistake is reported with its line and column.
  3. Keep Replace secrets with environment variables ticked unless you really want the literal values, and read the list of variables the code will need.
  4. Pick a language tab. For Rust, choose the async or the blocking client.
  5. Read the amber notes and the comments at the top of the code; they name every option that was ignored or behaves differently.
  6. Copy or download the code, set the variables (export API_TOKEN=... in a shell), and run it.

Example

A ticket request copied from the network panel, with an OAuth token in the query string

curl 'https://api.example.com/v1/tickets?status=open&access_token=ya29.a0AfB_byC1x2y3z4w5v6u7t8s9' \
  -H 'accept: application/json' \
  -H 'content-type: application/json' \
  --data-raw '{"subject":"Refund for order 5012","priority":2}'

Python requests, secrets option on

import os
from urllib.parse import quote

import requests

headers = {
    "accept": "application/json",
    "content-type": "application/json",
}

json_data = {
    "subject": "Refund for order 5012",
    "priority": 2,
}

response = requests.post(
    "https://api.example.com/v1/tickets?status=open&access_token=" + quote(os.environ["ACCESS_TOKEN"], safe=""),
    headers=headers,
    json=json_data,
)

print(response.status_code)
print(response.text)

(access_token was recognised by its name, so the page asks you to set
ACCESS_TOKEN. The Go tab sends the body as the raw string
`{"subject":"Refund for order 5012","priority":2}`.)

Tips for best results

  • Copy the request after it succeeded in the browser while you were logged in; a copy taken before login has no Cookie or Authorization header to convert.
  • Trim headers the server does not need before you commit the code. Chrome copies sec-ch-ua, sec-fetch-* and priority headers that a script almost never needs.
  • If a value should come from your shell, write it as "$TOKEN" in double quotes; the code then reads TOKEN from the environment with no further step.
  • For a large body, use --data-binary @payload.json and keep the file next to the script. The code reads it when it runs.
  • When the server rejects the generated request but accepts the curl command, run the command with curl -v and compare the headers with the code; the notes list every flag that was ignored.

Edge cases to watch

fetch, axios, requests, Go's client and reqwest follow redirects by default, while curl does not unless you pass -L. A 302 that curl printed can therefore turn into the page it pointed to. PHP is the exception: it follows only with CURLOPT_FOLLOWLOCATION, which the code adds when the command has -L.

requests treats timeout as a limit for connecting and for each read, not as a total like curl -m. The Python output carries a comment saying so.

Browsers do not let fetch set Cookie, Origin, Referer, Host or sec-* headers. The fetch output names the ones present and is meant for Node.

Digest, NTLM and Negotiate authentication (--digest, --ntlm, --negotiate) are not set up; the code uses basic authentication with the -u credentials and a note says so.

Files named with @ are never opened here. A body or upload read from a file becomes a file read in the code, and where a file is mixed with other data a <contents of ...> placeholder marks the spot.

-K config files, cookie files (-b file, -c), several requests joined with --next, URL globbing and PowerShell syntax are not converted.

Common errors and how to fix them

"This single quote is never closed" with a line and column
A quote in the command has no partner, usually because the command was cut short while copying, or because a value holds an apostrophe that was not escaped. In bash, write it as '\'' or use a $'...' string, or copy the full command again from the network panel.
"-H needs a value after it, but the command ends there"
The last flag lost its value, which often means a line continuation is missing. In bash every line but the last must end with a backslash; in cmd it must end with ^.
"No URL was found"
Every word was taken by a flag. A flag that needs a value probably took the URL as its value; check the flag before the URL, or pass the address with --url.
"-F (form upload) and -d (data) cannot be used together"
curl refuses this combination too. Send the fields as -F name=value parts, or send everything as -d form data.
"This is a PowerShell Invoke-WebRequest command, not curl"
Copy as PowerShell was chosen in the browser. Pick Copy as cURL (bash) or Copy as cURL (cmd) and paste that.
The JSON body appears as a string instead of an object
A body is rebuilt as an object only when the Content-Type header says JSON, the text parses, and every number fits a 64-bit float exactly; otherwise it stays text so nothing about it changes. Add -H 'Content-Type: application/json' to the command if the server expects JSON.

Best practices

  • Keep the secrets option on for any code that leaves your machine, and load the variables from a secrets manager or an untracked .env file.
  • Rotate a token that was ever pasted into chat, a ticket or a public repository; taking it out of the code does not undo the leak.
  • Remove browser-only headers once the request works, so the code shows what the server actually depends on.
  • Read the notes again after editing the command. A deleted backslash or quote changes which words are read as flags.

What Chrome's Copy as cURL writes, and how it is read back

In bash form Chrome wraps each argument in single quotes. If the argument contains a single quote, an exclamation mark or a control character, it switches to $'...' and writes those characters as escapes such as \' and \u0021. The reader decodes these escapes before anything else, so a body containing an apostrophe arrives in the code unchanged.

In cmd form Chrome escapes almost every punctuation mark with a caret, writes each double quote inside a value as ^\^", and doubles every backslash first. Read with the plain Windows rules, a backslash that is not followed by a quote would stay doubled; inside Chrome's ^"...^" wrappers the reader halves each pair and adds a note when it did, so a JSON body containing \n comes out the same as from the bash copy. Chrome also writes square and curly brackets in the URL as \[ and \{ so that curl's URL globbing leaves them alone, and the reader drops those backslashes as curl does.

How secrets are found and named

The Authorization header keeps its scheme and loses the credentials: Bearer and token values become API_TOKEN, Basic values become BASIC_AUTH, and anything else AUTHORIZATION. Proxy-Authorization becomes PROXY_AUTHORIZATION, the Cookie header COOKIE, -u becomes BASIC_AUTH_USER and BASIC_AUTH_PASSWORD, and proxy credentials PROXY_USER and PROXY_PASSWORD.

Other headers are replaced when the name mentions a key, token, secret, password, session, signature, credential or auth, so X-Api-Key becomes X_API_KEY, or when the value looks like a known token format: a JWT, a Stripe sk_ or rk_ key, a GitHub ghp_ or github_pat_ token, a GitLab glpat- token, a Slack xox token, an AWS AKIA key ID, a Google AIza key or ya29. token, an sk- key or a SendGrid SG. key. Query parameters are matched by name (access_token, api_key, key, token, secret, client_secret, password, signature, session and similar) or by the same value test, and their value is percent-encoded when the code runs.

A value that already reads a shell variable is left alone. When two secrets would get the same variable name, the second one gets _2.

Where the six outputs differ

fetch has no option to skip certificate checks, no proxy setting and no separate connect timeout, so -k, -x and --connect-timeout become comments, while -m becomes AbortSignal.timeout. Uploads use FormData with openAsBlob, which needs Node 20 or later. The axios output uses one config object with auth, timeout, an https.Agent for -k and a proxy object; repeated headers are joined into one value because an axios headers object holds each name once.

The Python output uses json= for JSON bodies, files= tuples for uploads, timeout=(connect, read) when --connect-timeout is given, verify=False for -k and a proxies dict. A string body with characters outside ASCII is encoded as UTF-8 first, because Python's http.client would otherwise encode it as Latin-1.

Go keeps a JSON body as the original text in a raw string literal, since a map would come out with its keys sorted. A transport cloned from http.DefaultTransport carries -k, -x and --connect-timeout, -m becomes the client's Timeout, and a Host header becomes req.Host because Go ignores it in req.Header. PHP gets a single curl_setopt_array call; JSON is rebuilt as a PHP array for json_encode, with an (object) cast where the keys would otherwise be read as a list, and an empty header is written as Name; which is how libcurl sends one.

Rust uses reqwest's ClientBuilder for -k, proxies and timeouts, serde_json::json! for JSON and multipart::Form for uploads, and lists the Cargo features it relies on in a comment. A secret in the query string is encoded by a small query_escape function added at the end of the file.

Where the code behaves differently from curl, and what is not converted

fetch, axios, requests, Go's client and reqwest follow redirects by default, while curl does not unless you pass -L, so a 302 that curl printed can turn into the page it pointed to. PHP follows only with CURLOPT_FOLLOWLOCATION, which the code adds when the command has -L. requests applies its timeout to connecting and to each read rather than to the whole request like curl -m, and a browser will not let fetch set Cookie, Origin, Referer, Host or sec-* headers, so the fetch output is meant for Node.

Credentials written into the URL, as in https://bob:secret@host/, are moved to basic authentication the way curl sends them, and the password is treated as a secret. Several -b options are joined with "; "; when -H also sets Cookie, curl sends only the -H value, and so does the code. Digest, NTLM and Negotiate authentication are not set up, files named with @ are read when the code runs rather than here, and -K config files, cookie files, requests after the first --next, URL globbing and PowerShell syntax are not converted.

Why the conversion happens in your browser

A copied request is a credential. The Cookie header from a logged-in session lets whoever holds it act as you until the session expires, and Authorization headers often carry long-lived API keys. Pasting that into a converter that posts it to a server hands your session to whoever runs the server and to whatever logs it keeps.

Here the command is parsed by the page's own script and the code is written in the same tab. The page makes no network request with it: the URL in the command is never contacted, files named with @ are never opened, and nothing is saved to the browser's storage.

Frequently asked questions

Does the converter send the request to test it?

No. It only writes code. Nothing is sent to the address in the command or to this site.

Which Rust client should I pick?

The async client suits programs that already run on tokio; the blocking client suits scripts and command-line tools and needs reqwest's blocking feature. The comment at the top of the output lists the Cargo dependencies and features for the choice you made.

Why does the Go code keep the JSON as a string?

Rebuilding it as a Go map would sort the keys and add a json.Marshal step. Sending the original text keeps the bytes identical to what curl sends.

What happens to variables that are already in the command?

$NAME or ${NAME} in bash, and %NAME% in cmd, become environment reads in every language: process.env.NAME, os.environ["NAME"], os.Getenv("NAME"), getenv('NAME') and std::env::var("NAME").