A cURL to code converter turns the curl command you copied from API documentation, a terminal or your browser into code you can paste into a program. Paste the command, choose JavaScript fetch, Python requests, PHP cURL, Node axios or Go net/http, and press Convert. The command is only read as text: nothing is run, no request is sent and nothing leaves your browser.
How the cURL to code converter reads a command
A curl command is a line of shell text, so the first job is to split it the way a shell would. The tool handles single quotes, double quotes with backslash escapes, the $'...' form that browsers produce with Copy as cURL, and a backslash at the end of a line that joins a long command across several lines. It then walks through the options one by one. This tokenizer is our own working; it covers the common cases but is not a full shell, so variables such as $TOKEN are kept as plain text.
Options the converter understands
- -X or --request sets the method. Without it the tool picks POST when there is a body or a form, HEAD for -I, and GET otherwise.
- -H or --header adds a header. A header with an empty value, such as Accept:, tells curl to drop that header, so the converter leaves it out and says so in the notes.
- -d, --data, --data-raw and --data-binary set the body. The curl manual says several data pieces are merged with an & between them and that the content type defaults to application/x-www-form-urlencoded. [1] The converter does the same and adds that header to the output so every language sends the same request.
- --data-urlencode percent-encodes the value, as the manual describes. [1]
- -G or --get moves the data into the query string of a GET request instead of the body. [1]
- -I or --head asks for the headers only. [1]
- -F or --form emulates a filled-in form sent as multipart/form-data. [1] A value starting with @ is a file path, which the converter turns into a file placeholder.
- --json sends the data as a POST and sets both Content-Type and Accept to application/json unless you overrode them. [1]
- -u or --user becomes Basic authentication in the target language.
- -b or --cookie becomes a Cookie header when the value contains an equals sign; the manual says a value without one is read as a file name, which the converter cannot do, so it adds a note. [1]
- -A and -e become User-Agent and Referer headers. [1]
- -L or --location tells curl to follow redirects; without it curl stops at the redirect response. [1]
- -k or --insecure skips certificate checks. [1] The tool does not copy that switch into the code. It adds a note instead, because turning off verification should be a deliberate choice in your own program.
What each language gets
| Language | Output | Redirects without -L |
|---|---|---|
| JavaScript fetch | await fetch(url, { method, headers, body }) | redirect set to manual |
| Python requests | requests.post(url, headers=..., data=...) | allow_redirects=False |
| PHP cURL | curl_setopt_array with CURLOPT_ options | CURLOPT_FOLLOWLOCATION false |
| Node axios | axios({ method, url, headers, data }) | maxRedirects set to 0 |
| Go net/http | http.NewRequest and client.Do | CheckRedirect returns ErrUseLastResponse |
In Python, a string passed as the body is posted exactly as given and no Content-Type header is added for you. [3] That is why the converter writes the header out itself. Requests follows redirects by default for every method except HEAD, and the allow_redirects argument switches that off, which is the setting the converter uses to match curl. [3] Multipart form fields are written as the files argument, and a path becomes an open() call in binary mode, the mode the Requests documentation recommends. [3]
Worked example
Take this command: curl -X POST https://api.example.com/items -H "Content-Type: application/json" -d '{"name":"Ada"}' -u ada:pw. The converter finds the POST method, one JSON header, the JSON body and the user ada with password pw. In JavaScript it writes a fetch call with method "POST", the header, the body string and an Authorization header built with btoa. In Python it writes requests.post with headers, data and auth=("ada", "pw"). In Go it writes a request with strings.NewReader for the body and SetBasicAuth for the login. These patterns are our own working based on how each library is normally used.
Reading the result
A browser fetch call does not reject when the server answers with an error such as 404 or 500; it rejects only when the request itself fails. [2] The generated JavaScript prints the status and body so you can see the answer, and you should add a check on response.ok before using the data in a real program. In Python, calling raise_for_status on the response does the same job. [3]
Limits and good habits
- Files named with @ are not read. The code contains a placeholder or a path for you to change.
- Secrets stay in the output. A command copied from a terminal often holds a live token or password, so remove them before sharing the generated code.
- Browsers block some headers and enforce cross-origin rules, so a fetch call that works in curl can fail in a web page. Run it from a server or a script when you need full control.
- Proxy, timeout, retry and output-file options are ignored because they describe how curl behaves, not what is sent.
- Check the generated code once against the original command, especially the method, URL and body.
Because everything runs in your browser, you can paste commands that contain internal URLs or keys while you work. Convert, copy the code, then clear the page.
What next
Use this often? Add cURL to Code to your Home screen.
Frequently asked questions
What does a curl to code converter do?
It reads a curl command and writes the same HTTP request as code in JavaScript, Python, PHP, Node or Go, with the method, URL, headers, body and login carried across.
Does the converter run my curl command?
No. The command is only split into parts and read as text in your browser. No request is made and nothing is uploaded.
Which curl options are supported?
Method, headers, data in its several forms, URL-encoded data, forms, JSON, Basic login, cookies, user agent, referer, follow redirects, get and head. Others such as timeouts and proxies are ignored.
Why does the code show redirects as off?
Curl does not follow a redirect unless you pass -L, so the generated code switches redirect following off to behave the same way.
Can it handle a command copied from browser developer tools?
Yes. It understands the dollar-quote strings and the line-ending backslashes that Copy as cURL produces, though shell variables are kept as plain text.
Is the generated code ready for production?
Treat it as a starting point. Add error handling, timeouts, and move secrets out of the source before you use it.
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.