How to use cURL to Code
- Paste the command into curl command. It must start with
curl(orcurl.exe). Multi-line commands with\at the line ends are fine. - Choose a language in Convert to: JavaScript — fetch, JavaScript — axios, Python — requests, PHP — cURL or Go — net/http.
- Copy or download the code (
request.js,request.py,request.phpormain.go). - Check the Parsed request table and the notes. Options the tool did not convert are listed there, so nothing is dropped silently.
What it does and when to use it
API docs usually give curl examples, and the browser can copy any request as curl. Turning one into application code by hand is slow and easy to get wrong, especially quoting, form encoding and auth. This tool does that translation for one request at a time.
It understands the options people use most: -X, -H, -d and its variants, --data-urlencode, --json, -F multipart uploads, -u basic auth, --oauth2-bearer, -A, -e, -b cookie strings, -G, -I, -L, -k, --compressed, -m and bundled flags such as -sSL or -XPOST. To go the other way, from fields to a command, use the cURL Builder.
How it works
The command is first split into words the way a POSIX shell would: single quotes, double quotes, $'…' strings and backslash continuations, with no variable expansion. curl’s options are then read into one request: method, URL, headers, body and auth. As in curl, a body without -X makes the method POST, and a body with no Content-Type header is sent as application/x-www-form-urlencoded. A JSON body becomes a real object in the generated code (JSON.stringify, json= in Python) when it parses as JSON.
Worked examples
A GitHub API call in Python. curl https://api.github.com/repos/octocat/hello-world -H "Accept: application/vnd.github+json" gives a headers dict and:
response = requests.get("https://api.github.com/repos/octocat/hello-world", headers=headers, allow_redirects=False)
curl –json to axios. curl --json '{"name":"Ana"}' https://x.io/users sets the method to post, adds Content-Type and Accept: application/json, and passes the body as an object:
data: {
"name": "Ana"
},
A GET with encoded parameters. curl -G https://x.io/search --data-urlencode "q=red shoes" -d limit=5 -k moves the data into the URL. The fetch output starts with a comment that -k cannot be copied, then:
const response = await fetch("https://x.io/search?q=red%20shoes&limit=5", {
redirect: "manual", // curl does not follow redirects without -L
});
Limits and tips
- One request per command. Pipes,
&&,$VARvalues and config files (-K) are not run or expanded. - File uploads (
-F file=@photo.jpg) become placeholders such asfileInput.files[0]in JavaScript; point them at your real file. - A URL without a scheme gets
http://, as curl does. - To decode a Basic auth header found in a command, use the Basic Auth Generator. To read a long URL from the command, use the URL Parser.
Frequently asked questions
Does "Copy as cURL" from Chrome or Firefox work?
Why does the Python code say allow_redirects=False?
What happens to -d @data.json?
Is my token sent anywhere?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.