Free cURL to Code Converter
Paste a cURL command and get equivalent code for Python, JavaScript, PHP, Go or Ruby. The parser respects single and double quotes, line continuations and common cURL flags, so JSON bodies and headers are converted correctly instead of being split naively on spaces.
Convert a cURL command
Paste a command from your terminal, browser DevTools (“Copy as cURL”), or API documentation. The command is never uploaded.
Your generated code will appear here.
How to use the cURL converter
- Paste the cURL command into the input box. You can include line continuations (
\at the end of a line). - Choose a target language. Python, JavaScript (fetch or axios), PHP, Go and Ruby are supported.
- Click Convert. The generated code appears on the right.
- Copy or download. Use the Copy button for the clipboard, or Download to save a file with the correct extension.
What this converter handles
- Request method with
-X/--request, or inferred from-d,-For-I. - URLs supplied as the final argument or with
--url. - Headers with
-H/--header, including duplicate header names. - JSON and raw bodies with
-d,--data,--data-raw,--data-binaryand--json. - URL-encoded bodies with
--data-urlencode. - Multipart forms with
-F/--form, including text fields and file fields (@file). - Basic authentication with
-u/--user. - Cookies with
-b/--cookie. - Proxy configuration with
-x/--proxy. - Redirect control with
-L/--locationand--no-location. - Insecure TLS with
-k/--insecure(where the target language supports it). - Compressed responses with
--compressed(adds anAccept-Encodingheader). - User-Agent and Referer shortcuts with
-Aand-e.
Supported flags
| Flag | Meaning | Conversion behavior |
|---|---|---|
-X, --request | HTTP method | Sets the method directly. |
-H, --header | Request header | Added to the headers object or array. |
-d, --data | Request body | Sets the body; method becomes POST unless overridden. |
--data-raw | Raw body | Same as -d for conversion purposes. |
--data-binary | Binary body | Same as -d for conversion purposes. |
--data-urlencode | URL-encoded body | Joined with & and passed as a body string. |
--json | JSON body | Sets Content-Type and Accept to JSON, and passes the raw body. |
-F, --form | Multipart form field | Generates a form-data object; @file is marked as a file field. |
-u, --user | Basic auth | Maps to auth in Python/JavaScript, CURLOPT_USERPWD in PHP, etc. |
-b, --cookie | Cookie header | Adds a Cookie header. |
-A, --user-agent | User-Agent header | Adds a User-Agent header. |
-e, --referer | Referer header | Adds a Referer header. |
-x, --proxy | Proxy URL | Maps to the proxy option where supported. |
-L, --location | Follow redirects | Enables redirect following where supported. |
--no-location | Do not follow redirects | Disables redirect following. |
-k, --insecure | Skip TLS verification | Disables certificate verification where the language allows it. |
-I, --head | HEAD request | Sets the method to HEAD. |
-G, --get | Send data as query string | Appends data to the URL and uses GET. |
--compressed | Request compressed response | Adds Accept-Encoding: gzip, deflate, br. |
Examples
JSON POST to Python requests
Input:
curl -X POST 'https://api.example.com/v1/users' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-d '{"name":"Ada Lovelace","email":"ada@example.com"}'
Output (Python):
import requests
url = "https://api.example.com/v1/users"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_TOKEN",
}
data = '{"name":"Ada Lovelace","email":"ada@example.com"}'
response = requests.request("POST", url, headers=headers, data=data)
print(response.status_code)
print(response.text)
Multipart form to JavaScript fetch
Input:
curl -X POST 'https://api.example.com/upload' \
-F 'name=report' \
-F 'file=@/path/to/report.pdf'
The fetch output uses a FormData object. The file path is kept as a comment because a browser cannot read a local path directly; you must supply a File object from an <input type="file"> element.
Limitations to know
- Shell parsing is not identical to every shell. The tokenizer handles POSIX-style single and double quotes, backslash escapes and line continuations. PowerShell and Windows
cmdquoting rules differ; commands copied from those environments may need adjustment. - Not every cURL flag is converted. Flags such as
-o,-i,-v,--trace,--retryand-Tare either ignored or warned about. Unsupported flags are listed in the warning area rather than silently dropped. - Browser fetch cannot disable TLS verification. The
-kflag is represented in Python, PHP, Go and Ruby, and in Node.js axios, but not in browserfetch(). The generated code notes this limitation. - Multipart file paths are not portable. A cURL command can read a local file with
@/path/to/file. Generated code must use the platform’s file API or a file input, so the path is preserved as a comment where appropriate. - Duplicate headers are preserved in the generated code where the language supports arrays, but some libraries combine them into a single comma-separated value. Check the final behavior if your API depends on duplicate headers.
- This tool does not execute the request. It only generates code. You are responsible for reviewing the output and adding error handling, timeouts and logging.
Frequently asked questions
Is this cURL converter free and private?
Yes. The converter is free and does not require an account. The command you paste is processed in your browser tab and is not uploaded to a server.
Does it handle JSON bodies with quotes correctly?
Yes. The tokenizer respects single and double quotes, so a JSON body wrapped in single quotes is not split on the spaces inside it. This is the main failure mode of simpler converters that split on whitespace.
Which languages are supported?
Python (requests), JavaScript (browser fetch), JavaScript (Node.js axios), PHP (cURL), Go (net/http) and Ruby (net/http).
Can I convert a command that uses -F for file uploads?
Yes, the form fields are parsed. File fields are marked as files. In Python, the generated code uses open(path, "rb"). In browser fetch, the generated code uses FormData and expects you to supply a File object, because a browser cannot read a local path.
Why does the tool warn about some flags?
Some cURL flags are about terminal output, retries, tracing or writing to a file. They do not map cleanly to an HTTP client library, or they would require platform-specific code. The converter warns you instead of silently ignoring them.
Does the generated code include error handling?
No. The snippets are intentionally minimal so they are easy to read and adapt. Add try/catch, status-code checks, timeouts and logging for production use.
Can I use this for API keys and tokens?
Yes, but review the generated code before sharing it. A cURL command copied from browser DevTools can contain cookies, bearer tokens or other secrets. The converter does not send the command anywhere, but the generated code will contain whatever credentials were in the command.
Why does the JavaScript fetch output mention redirect: "manual"?
cURL does not follow redirects by default. To preserve that behavior, the generated fetch code uses redirect: "manual" unless the command includes -L. Python requests follows redirects by default, so the generated Python code sets allow_redirects=False when -L is absent.