Curl To Code
Convert a raw curl command into fetch, Python, Axios or Go — instantly.
Updated:
curl command
Generated code
What is Curl To Code?
curl is a command-line tool for making HTTP requests, and browsers let you copy any network request as a ready-to-run curl command (e.g. from DevTools or an API's documentation) — but you usually need that same request written as real code, not a terminal command. Curl To Code parses a curl command and rewrites it as equivalent JavaScript fetch, Python (requests), Axios or Go code, so you can drop it straight into a project.
How to use Curl To Code
- Paste a curl command into the curl command box with the Paste button, type it in, or click Example to try a sample.
- Pick the output language — fetch, Python, Axios or Go — above the Generated code panel.
- Read the converted code as it updates instantly on the right.
- Click Copy to copy the generated code to your clipboard.
How curl-to-code conversion works
A curl command is really just a compact description of an HTTP request: a method, a URL, some headers and maybe a body. This tool tokenizes the command the way a real shell would — respecting single quotes, double quotes and backslash escapes — so a header value or JSON body containing spaces doesn't get cut in the wrong place, then maps each flag to the equivalent option in your target language:
// curl
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "Ada Lovelace"}'
// fetch
fetch("https://api.example.com/users", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "Ada Lovelace" })
});
Everything — tokenizing, parsing and code generation — runs with plain JavaScript in your browser. No external libraries, no server calls.
Examples
1. An authenticated GET request in fetch. API docs often show a curl command with a bearer token. Converting it to fetch gives:
curl https://api.github.com/user -H "Authorization: Bearer $GITHUB_TOKEN"
fetch("https://api.github.com/user", {
method: "GET",
headers: {
"Authorization": "Bearer $GITHUB_TOKEN"
}
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.error(err));
Note that $GITHUB_TOKEN is copied as literal text. The shell would replace it with the variable's value, but the converter doesn't, so swap it for process.env.GITHUB_TOKEN or your own secret store. If the token is a JWT, you can inspect its claims with the JWT Decoder.
2. A file upload with basic auth in Python. -u becomes auth= and -F "file=@…" becomes a files= entry. The method is POST because of -F:
$ curl -u admin:s3cret -F "[email protected]" https://files.example.com/upload import requests response = requests.post( "https://files.example.com/upload", auth=("admin", "s3cret"), files={ "file": open("report.pdf", 'rb') } ) print(response.status_code) print(response.json())
The generated code ends with response.json(), which assumes the server answers with JSON; paste the response into the JSON Formatter to read it. Every flag used here is documented in the curl man page.
Frequently asked questions
Is my curl command sent to a server?
No. The command is parsed and converted entirely in your browser with plain JavaScript; nothing is uploaded anywhere.
Which curl flags are supported?
-X/--request, -H/--header, -d/--data/--data-raw/--data-binary, -F/--form, -u/--user and --url. Common flags that don't affect the generated request, like -s, -v, -k or -L, are recognized and safely ignored.
Why does -d turn the request into a POST?
That's curl's own real behavior: passing -d/--data without an explicit -X defaults the method to POST. This tool mirrors that exactly, so the generated code matches what curl actually sends.
Does it handle quoted headers and JSON bodies with spaces?
Yes. The command is tokenized respecting single quotes, double quotes and backslash escapes, the same way a shell would — a naive split on spaces would cut a header value or JSON body in the wrong place.