By Tim King · Updated
cURL to Code Converter
Turn a curl Command Into Python Requests, Go, PowerShell and 24 Languages
OneTask is free, with no sign-up, and built by one person.
If this tool saved you time, a coffee helps keep new ones coming.
How the CURL Converter works
This curl to code converter turns a curl command into working code. Paste the curl command straight out of an API's documentation — line continuations and all — and get back the equivalent code in any of twenty-four targets, from Python and Go to PowerShell, Ansible, Kotlin and a raw HTTP request. Headers, JSON bodies, basic auth and form fields are all carried across, and nothing is sent anywhere.
Curl to code converter: flags mapped to code
Every API documents its endpoints as curl commands, because curl is the one HTTP client everybody has. Almost nobody ships curl commands, so the first thing you do with the example is translate it, and translation is exactly the kind of mechanical work that goes wrong when you are in a hurry — a header dropped here, a body sent as a form instead of JSON there.
The method is inferred, not always stated. A curl command with no -X sends a GET unless
there is a body, in which case it sends a POST. Documentation frequently relies on that, so a
command showing only -d is a POST even though nothing says so. Getting this wrong produces a
request that reaches the right URL and does the wrong thing, and the error message you get back
rarely points at the method.
JSON bodies and form bodies are genuinely different requests. -d '{"a":1}' with a JSON
content type is a JSON body; the same -d without that header is form-encoded, and curl will send
Content-Type: application/x-www-form-urlencoded by default. This is the single most common
translation bug: fetch will happily send your JSON string with the wrong content type, and the
server will reject it with a message about invalid form data that gives no hint of the real cause.
The converter reads the content type you supplied and picks the matching code shape.
Basic auth in curl is a flag, not a header. -u user:pass tells curl to base64-encode the pair
and build the Authorization header itself. Neither fetch nor requests does that from a
username and password string, so the translation has to be explicit — Axios and requests both take
an auth parameter, and fetch needs the encoded header constructed by hand.
Multipart form fields are an approximation. -F name=value tells curl to build a
multipart/form-data body with a generated boundary. A few targets have a first-class way to
express that — FormData in the browser, files= in requests — and those get the real thing.
Everywhere else the fields are folded into an ordinary URL-encoded body, which is the right shape
for simple text fields. File uploads (-F field=@file) are not converted: the tool says so, and you
add the file with the target language's own multipart helper.
curl does not follow redirects unless you ask it to. Without -L, a 301 or 302 comes back
as the response. Browser fetch does the opposite and follows by default, and requests follows
for most methods too. If the original command lacked -L, the faithful translation is one that
disables redirect following — otherwise your code silently does something curl never did.
Copying a command out of your browser's network tab is a security decision. "Copy as cURL" includes every cookie and authorisation header from that session, which is what makes it work and also what makes it a live credential. Strip the session headers before pasting the command anywhere, this tool included — everything here runs locally, but the same command pasted into a chat or an issue tracker is a leaked token.
FAQ
Which curl flags are supported?
The ones that shape the request: -X, -H, -d and its variants, -F, -u, -L, -k, -A,
-b, -e, -I, -T, -G and --url. Output and diagnostic flags such as -o, -s, -v and
-i are ignored because they describe curl's own behaviour rather than the HTTP request, though
the ones that take a value are still parsed so their value is never mistaken for the URL.
Why is my body sent as a string instead of JSON?
Because the command has no JSON content type. curl treats -d as form data by default, so add
-H 'Content-Type: application/json' to the command and the generated code will build a real JSON
body.
Does it handle multi-line commands with backslashes?
Yes. Backslash-newline continuations are joined before parsing, so you can paste a documentation example exactly as it appears without reformatting it into one line first.
Is the generated code production-ready?
It is a faithful translation of the request, not a finished integration. Add your own error handling, timeouts and retry policy, and move any credentials in the command into environment variables rather than leaving them inline.
See also: all Data & Code tools, Units, Images, Audio & Video, Documents.
Related tools
HTTP Status Codes
Look up what any HTTP status code actually means.
BPM To Milliseconds Calculator
Tempo to delay times in ms and Hz for every note value, and back.
Base Converter
Convert numbers between binary, octal, decimal and hex.
CSS Colour Converter
Convert CSS colours between hex, rgb, hsl, hwb, lab, lch and oklch.
Date To Words Converter
Write any date out in words for invitations, cheques and documents.