cURL to Code Converter

Convert a curl command into Python, JavaScript, Go and 8 more languages

What is a cURL to code converter?

A cURL to code converter turns a curl command — the kind you copy from API documentation, your browser’s “Copy as cURL” menu, or a Postman export — into ready-to-run source code in the language of your choice. Instead of manually translating flags like -X, -H, -d, and -u into your HTTP client’s API, you paste the command and get working code for Python, JavaScript, Go, PHP, and eight more targets in a fraction of a second. Everything happens client-side: your command, tokens, and request bodies never leave your browser.

curl is the universal language of HTTP examples. Almost every API — Stripe, GitHub, OpenAI, your own backend — documents its endpoints as curl one-liners because they are copy-paste runnable from any terminal. The problem starts the moment you need that same request inside an application. Now you have to know that curl’s -d maps to data= in Python requests but body: in fetch, that -u becomes SetBasicAuth in Go, and that a -F upload needs MultipartFormDataContent in C#. This tool encodes all of those mappings so you don’t have to remember them.

How to convert a curl command to code

  1. Paste your curl command into the input area above. Multi-line commands with \ line continuations are fine — paste them exactly as they appear in the docs.
  2. Choose a target language from the selector (Python – requests is the default).
  3. Click Convert or press Ctrl+Enter. The generated code appears instantly.
  4. Copy the result with the Copy button or Ctrl+Shift+C and drop it into your project.
  5. Clear the workspace with Ctrl+L when you’re done.

The output also updates live as you type, so you can tweak a header or the body and watch the code change without clicking anything.

Supported languages and libraries

The converter emits idiomatic code for eleven popular targets:

LanguageClient used
Pythonrequests (also httpx)
JavaScriptfetch (browser / Node 18+)
Node.jsaxios
PHPthe cURL extension
Gonet/http
Rubynet/http
C#HttpClient
Javajava.net.http (Java 11+)
Rustreqwest (blocking)
PowerShellInvoke-RestMethod

Each generator uses the standard, widely-installed client for that ecosystem, so the code compiles and runs with minimal setup — no exotic dependencies.

Which curl flags the converter understands

Real-world curl commands lean on a small set of flags, and the parser handles all of the common ones:

  • -X / --request — the HTTP method (GET, POST, PUT, DELETE, PATCH, …). If you omit it, the method is inferred: POST when a body or form is present, otherwise GET.
  • -H / --header — request headers. Every header is preserved in order.
  • -d / --data / --data-raw / --data-binary / --data-urlencode — the request body. Multiple -d flags are joined with &, exactly like curl.
  • -G / --get — send the data as a query string on a GET request instead of in the body.
  • -F / --form — multipart form fields and file uploads (field=@file).
  • -u / --user — HTTP basic authentication (user:password).
  • -b / --cookie, -A / --user-agent, -e / --referer — mapped to the corresponding Cookie, User-Agent, and Referer headers.
  • -I / --head — a HEAD request.
  • -k / --insecure — disable TLS certificate verification (translated to the right option per language).
  • -L / --location, --compressed, --url — recognized and handled where relevant.

Flags that only affect terminal behavior — -s, -v, -o, --connect-timeout, and friends — are safely ignored, so pasting a command straight from a shell script just works.

Headers, JSON bodies, and authentication

Two details trip people up when they translate curl by hand, and the converter gets both right:

The Content-Type default. If you send a body with -d but never specify a Content-Type, curl quietly defaults to application/x-www-form-urlencoded. Many developers assume -d '{"a":1}' sends JSON — it does not, unless you add the header. The converter mirrors curl’s true behavior and inserts the urlencoded default so your generated code behaves identically to the command you tested. Add -H 'Content-Type: application/json' when you actually want JSON.

Authentication. A bearer token in -H 'Authorization: Bearer …' is copied through as a header. Basic auth from -u user:pass is translated to each language’s native helper — auth=(user, pass) in Python, req.SetBasicAuth(...) in Go, request.basic_auth(...) in Ruby, or a base64 Authorization: Basic header where that’s the idiomatic approach. Because everything is generated locally, your token never touches a network.

Multipart form uploads

File uploads are where hand-translation gets ugly, because every language builds multipart bodies differently. Write the upload the curl way:

curl -X POST https://api.example.com/upload \
  -F "avatar=@profile.png" \
  -F "user_id=42"

…and the tool produces the correct multipart request for the target: a files dict in Python requests, a FormData object in JavaScript, a multipart.NewWriter in Go, a MultipartFormDataContent in C#, request.set_form([...], 'multipart/form-data') in Ruby, and so on. File fields (@path) become a file-open call in the generated code — point the path at the real file on disk and it’s ready to run.

Common issues and how to fix them

  • Unterminated quotes. If you paste half a command or a quote is missing, the parser reads to the end of the input. Make sure the command is complete and quotes are balanced.
  • Windows vs. Unix line breaks. Docs sometimes use ^ (cmd) or a backtick (PowerShell) for line continuation instead of the Unix \. Convert those to \ — or just put the whole command on one line — before pasting.
  • -d @file.json. curl can read a body from a file with @. The converter keeps the literal @file.json text rather than inventing a file read; swap it for the file’s actual contents or add a read call yourself.
  • The wrong Content-Type. As above, -d without a Content-Type header produces urlencoded, not JSON. Add the header if your API expects JSON.

curl to Python: a worked example

Paste this:

curl -X POST https://api.example.com/v1/login \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk_test_123" \
  -d '{"email":"me@example.com","remember":true}'

…select Python – requests, and you get:

import requests

url = "https://api.example.com/v1/login"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer sk_test_123",
}
payload = "{\"email\":\"me@example.com\",\"remember\":true}"
response = requests.post(url, headers=headers, data=payload)
print(response.text)

Switch the target to Go, PHP, or C# and the same request is re-expressed in that language’s conventions — no manual rewriting.

When you reach for a curl converter

  • Shipping code from a shell prototype. You proved an integration works with a quick curl command; now you need it in your app’s language.
  • APIs that only document curl. Many providers give a single curl example and expect you to translate it. This does that instantly for whichever stack you’re on.
  • Porting between languages. Moving a service from Ruby to Go, or a script from Python to Node? Round-trip the request through curl and out the other side.
  • “Copy as cURL” from the browser. Grab a request from your DevTools Network tab as curl, paste it here, and get client code that reproduces it.

curl to code vs. writing it by hand

Translating a curl command manually is doable for a simple GET, but it gets error-prone fast: forgetting curl’s urlencoded default, mishandling an escaped quote inside a JSON body, or wiring up multipart uploads by hand are all easy ways to introduce a bug that only shows up at runtime. A converter removes that whole class of mistakes and turns a two-minute translation into a two-second paste. Use it as a starting point, then adjust the generated code — timeouts, error handling, response parsing — to fit your codebase. When your response comes back as JSON, run it through a JSON formatter to read it, or generate types for it with the JSON to TypeScript converter.

Frequently Asked Questions

How do I convert a curl command to Python?

Paste your curl command into the input box, choose 'Python – requests' (the default) as the target language, and click Convert or press Ctrl+Enter. The tool parses the command's method, URL, headers, body, and authentication, then emits ready-to-run Python using the requests library. Switch the target to 'Python – httpx' if you prefer the modern httpx client. Copy the result with one click and paste it straight into your script.

Does this tool send my curl command or data to a server?

No. The entire conversion runs in your browser using JavaScript. Your curl command — including any API keys, bearer tokens, cookies, or request bodies it contains — is parsed and turned into code locally. Nothing is uploaded, logged, or stored. You can verify this by opening your browser's Network tab: there are no outbound requests while you convert. That makes it safe to paste commands that contain real credentials.

Which languages can I convert a curl command to?

Eleven targets are supported: Python (requests and httpx), JavaScript (fetch), Node.js (axios), PHP (the cURL extension), Go (net/http), Ruby (net/http), C# (HttpClient), Java (java.net.http), Rust (reqwest), and PowerShell (Invoke-RestMethod). Pick the target from the language selector below the tool; the output updates instantly when you switch.

How are request headers and JSON bodies handled?

Every -H / --header flag becomes a header entry in the generated code, in the same order you wrote them. A -d / --data body is passed through verbatim as the request body, so the exact bytes you send with curl are the bytes your code sends. If you supply a body with -d but no Content-Type header, the tool adds application/x-www-form-urlencoded to match curl's real default behavior — add -H 'Content-Type: application/json' if you meant to send JSON.

Can it convert curl requests that use basic authentication?

Yes. A -u user:password flag is mapped to each language's native basic-auth mechanism — auth=(user, pass) in Python requests, SetBasicAuth in Go, request.basic_auth in Ruby, an Authorization: Basic header in fetch and PowerShell, and so on. The credentials are never sent anywhere; they are only written into the code you copy.

How do I convert a curl file upload (-F multipart form data)?

Use -F name=value for text fields and -F field=@path/to/file for file uploads, exactly as you would with curl. The converter builds the correct multipart request for each language — a files dict in Python requests, FormData in JavaScript, multipart.NewWriter in Go, MultipartFormDataContent in C#, and so on. For file fields, the generated code opens the file by the path you referenced, so adjust that path to point at the real file on disk.

Why does the generated code sometimes set Content-Type to x-www-form-urlencoded?

When you pass a body with -d but don't specify a Content-Type header, curl itself defaults to application/x-www-form-urlencoded — so the converter reproduces that default to keep the generated request faithful to what curl actually does. If your API expects JSON, add -H 'Content-Type: application/json' to your curl command (or edit the header in the output) and the generated code will send JSON instead.