Skip to content
Devtoolry

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

  1. Paste a curl command. Bash quoting is understood, as are line continuations from bash (\), cmd.exe (^) and PowerShell (`).
  2. Choose the language and library in the Language menu.
  3. Read any Note comments at the top of the code: they list options that were ignored or cannot be expressed in that language.
  4. Copy the code or download it as a file, then replace placeholders such as file paths and tokens.

Examples

Multipart upload with basic auth (Python)

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.

Authenticated GET (JavaScript fetch)

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

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.