cURL to Code Converter
Paste a cURL command and get equivalent code for JavaScript fetch, Node.js Axios, Python requests or Go net/http.
How to use this tool
Steps for using the cURL to Code.
- Copy a curl command from API documentation, a README or your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
- Paste it into the cURL command panel, or click Sample to load an example. Multi-line commands with
\continuations are fine. - Pick the output language: JavaScript fetch, Node.js Axios, Python requests, Go net/http or PHP cURL. The code updates as you type.
- Read any notes under the editors — options that have no equivalent (for example
--proxyor-m) are listed rather than silently dropped. - Replace placeholders such as
YOUR_TOKENor file paths, then Copy the code or Download it with the right file extension.
Example
POST JSON with a bearer token → JavaScript fetch
curl -X POST 'https://api.example.com/v1/users?notify=true' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{"name":"Ada Lovelace","email":"ada@example.com","roles":["admin","editor"]}'const response = await fetch('https://api.example.com/v1/users?notify=true', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
"name": "Ada Lovelace",
"email": "ada@example.com",
"roles": [
"admin",
"editor"
]
})
});
const data = await response.json();
console.log(response.status, data);Common use cases
- Turning the curl examples in API docs (Stripe, GitHub, OpenAI and similar) into code for your stack.
- Reproducing a request captured with Copy as cURL in Chrome or Firefox DevTools inside a script or test.
- Porting a shell script that calls an API to Python, Go or Node.js.
- Checking exactly which method, headers and body a long curl one-liner sends before you run it.
- Building a multipart file-upload request without looking up each library's form API.
How the curl command is parsed
A curl command is shell syntax before it is an HTTP request, so the converter first splits it into words the way bash would. Single quotes keep their contents literally, double quotes honour backslash escapes for ", \, $ and backticks, $'…' strings decode ANSI-C escapes such as \n and \x41, and a backslash at the end of a line (or a caret ^ in Windows cmd syntax) joins the next line. Shell variables like $TOKEN are not expanded — they stay in the output as written, so replace them before running the code.
The words are then interpreted with curl's own rules. -d, --data-raw, --data-binary and --data-urlencode are joined with & and imply a POST; -G moves that data into the query string instead; --json sets both Content-Type and Accept to application/json; -F builds a multipart form; -u becomes HTTP Basic authentication; -b, -A and -e become Cookie, User-Agent and Referer headers. Combined short flags such as -sSL, attached values such as -XPUT and the --header=value form are all understood. An explicit -X always wins over the method curl would infer.
One subtle curl behaviour is preserved deliberately: when you send data with -d and no Content-Type header, curl labels it application/x-www-form-urlencoded — even if the body is JSON. The converter adds that header explicitly so the generated code sends exactly what curl would, and shows a note suggesting -H 'Content-Type: application/json' if that was the intent.
JSON bodies are pretty-printed and emitted idiomatically — JSON.stringify({...}) for fetch, a plain object for Axios, a json= dict for requests, a raw string literal in Go — but only when re-serialising cannot change the bytes on the wire. A body containing a 64-bit ID such as 12345678901234567890, a 1.0 or an escaped character is kept verbatim instead, because JSON.parse would silently alter it. Every string is escaped for its target language, so quotes, backslashes and newlines in headers or bodies cannot break the generated code.
Limitations
- Shell variables, command substitution (
$(...)) and pipes are not evaluated; only a single curl invocation is converted. - Files referenced with
-d @file,-F field=@fileor--data-binary @filebecome placeholders or file-reading code — their contents are never read. - Transport options such as
--proxy,--cacert,-m/--max-time,--retryand HTTP version flags are reported as notes, not translated. - The fetch, Axios, requests and Go output follow redirects (each library's default) even when
-Lis absent, and the fetch output cannot disable certificate checks for-k. - Only the first URL is converted when a command contains several.
Frequently asked questions
Is the curl command, including my tokens, sent anywhere?
No. Parsing and code generation run entirely in your browser; nothing is uploaded or logged. Commands copied from DevTools often contain session cookies and bearer tokens, so it is still worth replacing them with placeholders before sharing the generated code.
Why does my -d request get a form Content-Type instead of JSON?
Because that is what curl itself sends. -d without a Content-Type header uses application/x-www-form-urlencoded. Add -H 'Content-Type: application/json' to the command, or use --json, and the converter will emit a JSON body.
What happens to options the converter does not support?
They are listed in a note under the editors — for example "Unknown option --frobnicate was ignored" or "--proxy is not translated". Purely cosmetic options such as -s, -S, -v, -i and -o are ignored silently because they do not change the request.
Can I convert a command copied from Windows (cmd) DevTools?
Line continuations with ^ are understood, but cmd's ^" quote escaping is not. In Chrome or Edge DevTools choose Copy as cURL (bash) rather than the cmd variant for reliable results.
Does the fetch code run in Node.js too?
Yes, in Node.js 18 or later, which has a global fetch, inside an ES module (top-level await). The Axios output is downloaded as request.mjs for the same reason. See the curl to JavaScript guide for a walkthrough.