curl to Code Converter (fetch, Python, Go, PHP)
Turn a curl command into fetch, axios, Python, Go, PHP or HTTPie code.
Use via API
Convert a curl command into equivalent code: JavaScript fetch, Node.js axios, Python requests, Go net/http, PHP curl or HTTPie. Handles headers, -d/--data*, -F forms, -u auth and common flags; unsupported options come back as warnings. Send JSON, get JSON back.
POST https://pithlab.com/api/v1/tools/curl-converter
curl https://pithlab.com/api/v1/tools/curl-converter \
-H "Authorization: Bearer $PITHLAB_KEY" \
-H "Content-Type: application/json" \
-d '{"command":"curl -X POST https://api.example.com/v1/items -H '\''Content-Type: application/json'\'' -H '\''Authorization: Bearer TOKEN'\'' -d '\''{\"name\":\"Widget\"}'\''","target":"python"}'About the curl Converter
Convert curl commands to JavaScript fetch, Node axios, Python requests, Go net/http, PHP curl or HTTPie. Handles headers, data, forms, auth and cookies in your browser.
How to use the curl Converter
- Paste a curl command, for example one copied with Copy as cURL from your browser's network tab.
- Pick the language you want: JavaScript fetch, Node axios, Python requests, Go, PHP or HTTPie.
- The code updates as you type. Read any warnings about options that could not be converted.
- Copy the code or download it as a file.
Examples
Input
curl -X POST https://api.example.com/users -H 'Content-Type: application/json' -d '{"name":"Ada","admin":true}'Output
import requests
headers = {
"Content-Type": "application/json",
}
json_data = {
"name": "Ada",
"admin": True,
}
response = requests.post("https://api.example.com/users", headers=headers, json=json_data)
print(response.status_code)
print(response.text)
Input
curl -u admin:s3cret -F title=Report -F [email protected] https://example.com/upload
Output
const form = new FormData();
form.append("title", "Report");
form.append("file", new File([/* contents of report.pdf */], "report.pdf"));
const response = await fetch("https://example.com/upload", {
method: "POST",
headers: {
"Authorization": "Basic YWRtaW46czNjcmV0",
},
body: form,
});
console.log(response.status);
console.log(await response.text());
Input
curl -L 'https://example.com/search' -G --data-urlencode 'q=hello world' -H 'Accept: text/html'
Output
http --follow 'https://example.com/search?q=hello%20world' Accept:text/html
Frequently asked questions
Does this tool run my curl command?
No. The command is only parsed as text in your browser and turned into code. Nothing is executed and no request is sent, so it is safe to paste commands that contain tokens.
Which curl options are supported?
Methods (-X), headers (-H), data (-d, --data-raw, --data-binary, --data-urlencode, --json), form fields (-F), basic auth (-u), cookies (-b), -G, -L, -k, -A, -e, -I and --compressed. Anything else is listed as a warning.
Can I paste a command copied from Chrome or Firefox?
Yes. Both the bash and the Windows cmd versions of Copy as cURL work, including line continuations with backslash or caret, single and double quotes, and $'...' strings.
What happens to options that read files, like -d @data.json?
The tool cannot read files from your computer, so the file name is kept as a placeholder and a warning is shown. File uploads with -F name=@file become real file uploads in the code.
Why do redirects behave differently?
curl only follows redirects when you pass -L, but fetch, axios, requests and Go follow them by default. PHP and HTTPie do not, so -L turns on following there.