cURL to Code
Convert curl commands to Python requests, JavaScript fetch, axios, Go, PHP or Java code online. Headers, JSON bodies, forms, auth and timeouts carry over.
Something not working, or missing a feature? Send feedback
About the cURL to Code
cURL to Code turns a curl command into the same HTTP request in JavaScript (fetch), Node.js (axios), Python (requests), Go (net/http), PHP (cURL) or Java (HttpClient). Paste a command from API documentation, your terminal or the browser's "Copy as cURL" and get code that sends the same method, URL, headers, body, authentication and timeout. The conversion runs in your browser, so tokens in the command stay private.
Conversion happens in your browser, so your files and records stay private.
How to use the cURL to Code
- Paste a curl command. Bash quoting is understood, as are line continuations from bash (\), cmd.exe (^) and PowerShell (`).
- Choose the language and library in the Language menu.
- Read any Note comments at the top of the code: they list options that were ignored or cannot be expressed in that language.
- Copy the code or download it as a file, then replace placeholders such as file paths and tokens.
Examples
Input
curl -u ada:s3cret -F 'title=Q3 report' -F '[email protected];type=application/pdf' https://api.example.com/upload
Result
import requests
files = {
'title': (None, 'Q3 report'),
'file': ('report.pdf', open('report.pdf', 'rb'), 'application/pdf'),
}
response = requests.post(
'https://api.example.com/upload',
files=files,
auth=('ada', 's3cret'),
)
print(response.status_code, response.text)Text fields become (None, value) tuples, so requests sends one multipart body in the same order as curl.
Input
curl 'https://api.example.com/search?q=devtools' -H 'Accept: application/json' -H 'Authorization: Bearer YOUR_TOKEN'
Result
const response = await fetch('https://api.example.com/search?q=devtools', {
headers: {
Accept: 'application/json',
Authorization: 'Bearer YOUR_TOKEN',
},
});
console.log(response.status, await response.text());GET is the default method, so it is left out.
Common mistakes
- Pasting secrets into code. Commands copied from the browser carry cookies and bearer tokens. Replace them with environment variables before committing the code.
- Using "Copy as cURL (cmd)". The Windows cmd variant escapes with ^ inside quotes, which is hard to parse reliably. Copy the bash version instead; it works on every platform here.
- Expecting -k in the browser. Browsers never let fetch skip certificate checks. The fetch output notes this; fix the certificate or test against a host with a valid one.
Works well with the cURL to Code
- JSON Formatter: read the JSON body of the request.
- URL Parser: inspect the query string of the URL.
- JWT Decoder & Verifier: decode a bearer token from the command.
Frequently asked questions
Which curl options are converted?
The request itself: -X, -H, -d and its --data-raw, --data-binary, --data-urlencode and --json variants, -F multipart forms with files, -u basic auth, -b cookies, -A, -e, -G, -I, -L, -k, -m and --oauth2-bearer. Output options such as -s, -v, -i, -o and --compressed are dropped silently; anything else is listed in a Note comment.
Why does the code add Content-Type: application/x-www-form-urlencoded?
Because curl sends that header with -d when you do not set one, and most libraries would not. Writing it out keeps the request identical, which matters for servers that parse the body by content type.
Does the generated code follow redirects like curl?
curl follows redirects only with -L. fetch, axios, requests and Go follow them by default, so -L adds nothing there; PHP's cURL and Java's HttpClient do not, so -L turns on CURLOPT_FOLLOWLOCATION and Redirect.NORMAL.
How do I copy a request from the browser as curl?
Open the developer tools, go to the Network tab, right-click the request and choose Copy > Copy as cURL (bash). The bash version uses $'...' quoting for special characters, which this tool understands. Remove cookies and tokens you do not want in your code.
Related tools
JSON to CSV
Convert JSON arrays to CSV online with automatic column detection, nested object flattening and custom delimiters. Open the result in Excel or Sheets.
CSV to JSON
Convert CSV to a JSON array online with header detection, type inference and delimiter auto-detection. Turn spreadsheet exports into data for APIs and code.
JSON to XML
Convert JSON to well-formed XML online with a configurable root element and attribute support. Validate the input and download the XML file.
XML to JSON
Convert XML to JSON online, keeping attributes and turning repeated elements into arrays. Malformed XML is reported with its location.
JSON to YAML
Convert JSON to clean, human-readable YAML online. Turn API responses and package files into config for Kubernetes, Docker Compose or CI pipelines.
YAML to JSON
Convert YAML documents to formatted JSON online with syntax validation. Errors are reported by line, so broken indentation is quick to find and fix.