Skip to content
ToolBoxGeniehome

curl to Code Converter

Developer Tools · Added

Every API's documentation gives you a curl command, and you need it in something else. Paste it here and get working code for fetch, axios, Python requests or Node's https module, with headers, body and auth carried across rather than approximated.

Chrome's devtools give you one: right-click a request, Copy, Copy as cURL.

Works in browsers and in Node 18 and later

Try:

How to use the curl to code converter

  1. 1Copy the curl command from the documentation, or from your browser's Copy as cURL.
  2. 2Paste it in — line continuations and multi-line commands are fine.
  3. 3Pick the target language or library.
  4. 4Read the notes about any flag that has no direct equivalent before using the output.

Examples

A POST with a JSON body

Input
curl -X POST https://api.example.com/v1/items -H "Content-Type: application/json" -d '{"name":"widget"}'
Result
A fetch call with method, headers and body set, awaiting response.json() — or the equivalent requests.post with a headers dict in Python.

A request with basic auth

Input
curl -u user:pass https://api.example.com/status
Result
An Authorization header built from the encoded credentials, with a note that the password is now sitting in your source rather than in a shell history.

About the curl to code converter

The mismatches worth knowing about

A curl command and its equivalent in another language are rarely a line-for-line match, because the defaults differ. curl does not follow redirects unless told; fetch follows them automatically. curl verifies TLS certificates unless you pass -k; Python's requests does the same but warns differently. curl sets no timeout at all by default, while some libraries impose one.

Those defaults are where translated requests go wrong, and they go wrong quietly — the request succeeds, it just does something slightly different from the one in the documentation. The generated code here sets them explicitly rather than relying on whichever default happens to apply.

Credentials do not survive the journey

A curl command pasted from documentation usually carries a placeholder token. A curl command copied from your own terminal usually carries a real one, and converting it moves that secret from a shell history into a source file that may well end up committed.

Nothing here is uploaded — the parsing and generation happen entirely in your browser — but the output is still code with a secret in it. The five seconds it takes to replace the literal with an environment variable read is the whole of the fix, and it is worth doing before the file is saved rather than after.

Frequently asked questions

Which curl flags are supported?
The ones that appear in API documentation: the request method, headers, data in its several forms, form fields, basic auth, cookies, redirect following, timeouts and the insecure switch. Anything unrecognised is listed explicitly rather than dropped, because a flag silently disappearing from a request is a far worse outcome than being told it was not handled.
Does it handle shell quoting properly?
Yes. The command is tokenised under POSIX shell rules, so single quotes are taken literally, double quotes allow escapes, backslash-newline continuations are joined, and a JSON body full of quotes survives intact. What it deliberately does not do is expand variables or run substitutions — $TOKEN stays as the literal text $TOKEN.
Is the generated code safe to paste straight in?
It is a faithful translation, not a finished implementation. Error handling is minimal, and any credential in the original command comes across as a literal string that belongs in an environment variable instead. Read it as a starting point that gets the request shape right, which is the tedious part.
Why does the output not follow redirects unless I asked for it?
Because curl does not either. Without -L, curl hands you the 302 and stops, so a generated request that quietly followed it would behave differently from the command you pasted. fetch defaults the other way, which is exactly the kind of mismatch that turns into a confusing bug, so the setting is always made explicit in the output.