curl to code
Paste a curl command and get the same request in Python, JavaScript, Go or PHP. Works with commands from API docs and your browser's Copy as cURL.
How to convert a curl command
- Copy the command. From API docs, a terminal, or your browser: open DevTools, Network tab, right-click a request, Copy, Copy as cURL (bash or cmd both work).
- Paste it on the left. Pick Python, JavaScript, Go or PHP. The code updates as you type.
- Check the notes. If the command reads a file (
-d @data.json,-F file=@photo.png) or uses a proxy or client certificate, a note says what to fill in.
Supported curl options
| Option | Meaning |
|---|---|
| -X, --request | HTTP method |
| -H, --header | Request header (-H 'Name;' sends it empty) |
| -d, --data, --data-raw, --data-binary | Body; makes it a POST with form encoding unless a Content-Type is set |
| --json | JSON body with JSON Content-Type and Accept headers |
| --data-urlencode | URL-encodes the value |
| -F, --form | Multipart form fields and file uploads |
| -G, --get | Sends the -d data in the query string |
| -u, --user | Basic authentication |
| -b, -A, -e | Cookie, User-Agent and Referer headers |
| -L, -k, -m, -I, -T | Follow redirects, skip TLS checks, timeout, HEAD, upload a file |
Questions
Is my curl command sent anywhere?
No. It's converted in your browser, so tokens and cookies in the command never leave your machine.
How do I copy a request from my browser as curl?
Open DevTools (F12), go to the Network tab, right-click the request and choose Copy, then Copy as cURL. Paste it here.
Does the fetch code follow redirects?
Yes. fetch always follows redirects, even without -L, and browsers can't turn that off. In Node you can add redirect: "manual" to stop at the first response.
Why does the Python code have allow_redirects=False?
curl doesn't follow redirects unless you pass -L, so the code does the same. Remove it, or add -L to the command, to follow them.
What happens with -d @file.json?
The code gets a placeholder where the file's contents go, and a note tells you which file it was.
Does -k work in JavaScript?
No. fetch can't turn off certificate checks, so the code includes a comment instead. Python, Go and PHP get the equivalent setting.