curl to Code Converter
Convert a curl command to JavaScript fetch, Node axios, Python requests, PHP, Go, Java, C# or Ruby. Handles headers, JSON, forms and auth. Nothing is sent.
How to use curl to Code Converter
- 1Paste a curl command, including multi-line commands with backslashes, or open a text file.
- 2In Convert mode choose JavaScript fetch, Node.js fetch or axios, Python, PHP, Go, Java, C# or Ruby. In Parse mode read the structured breakdown instead.
- 3Copy or download the code, read the notes about anything the target library does differently, and replace any credentials before you share it.
What makes it better
- Understands -X, -H, -d and the other data options, --json, -u, -F, -b, -A, -e, -G, -L, -k, -I, -m, --compressed and --url
- JSON bodies are pretty-printed in the generated code when they are valid JSON
- Warns when the command contains an Authorization header, -u credentials, cookies or tokens that will end up in the code
- Lists the flags it ignored, such as -s or -o, instead of silently dropping them
- Two modes on one page: Convert and Parse
About curl to Code Converter
Paste a curl command, for example one copied from API documentation or your browser's developer tools, and this page turns it into ready-to-edit code in nine variants across eight languages. It has its own shell-style parser that understands quotes, line continuations and the options that change a request, and its Parse mode shows the method, URL, headers, body and credentials as a table. The command is only read: nothing is executed and no request is sent.
Common uses
- Turn a curl example from an API reference into the HTTP client your project already uses.
- Replay a request copied from the browser's Network tab as a Python script.
- Check what a long curl command with many -H and -d options actually sends.
- Port a shell script's health check to Go or Java without retyping the headers.
Example
Input
curl -X POST https://api.example.com/v1/orders \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{"item":"book","qty":2,"gift":true}'Result
const response = await fetch("https://api.example.com/v1/orders", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
"item": "book",
"qty": 2,
"gift": true
}),
});
console.log(response.status);
console.log(await response.text());
Good to know
- The command is never run and files named with @ cannot be read in a browser. They appear as placeholders in the code and a note says so.
- Shell variables such as $TOKEN are not expanded. They are kept as literal text so you can replace them. Only the first command is converted if the line contains a pipe or &&.
- Generated code is a starting point. Libraries differ from curl in redirects, compression, timeouts and TLS, and the notes under the code point out the main ones.
curl to Code Converter FAQ
Which curl options can this converter read?
Method and URL (-X, --request, --url), headers (-H), body data (-d, --data, --data-raw, --data-binary, --data-urlencode and --json), basic and bearer authentication (-u, --oauth2-bearer), multipart forms (-F), cookies (-b), user agent (-A), referer (-e), -G, -L, -k, -I, -m and --compressed. Other flags such as -s, -v or -o are recognised and listed as ignored because they do not change the request.
Is it safe to paste a command that contains an API key?
The command is parsed on this page and never executed, but the generated code contains the key exactly as written, and the page shows a warning when it spots an Authorization header, -u login, cookie or token. Replace secrets with environment variables or placeholders before you commit or share the output.
Why does the generated code add a Content-Type header I did not write?
When you send data with -d and no Content-Type, curl itself adds application/x-www-form-urlencoded. The converter makes that header explicit so the code behaves like the original command, and it tells you it did so. Use --json or your own -H to send something different.
Can it convert a command that uploads a file?
Partly. Options such as -F '[email protected]' produce code that reads the file from the path you gave, and a note reminds you to check that path. A browser page cannot open your files, so a body read with -d @file or --json @file appears as a placeholder rather than the file's contents.