navaja.dev / curl

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

Supported curl options

OptionMeaning
-X, --requestHTTP method
-H, --headerRequest header (-H 'Name;' sends it empty)
-d, --data, --data-raw, --data-binaryBody; makes it a POST with form encoding unless a Content-Type is set
--jsonJSON body with JSON Content-Type and Accept headers
--data-urlencodeURL-encodes the value
-F, --formMultipart form fields and file uploads
-G, --getSends the -d data in the query string
-u, --userBasic authentication
-b, -A, -eCookie, User-Agent and Referer headers
-L, -k, -m, -I, -TFollow 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.