🔄 cURL to Code Converter
Convert curl commands to Python, Node.js, and Java code — instantly
Paste a curl command and instantly convert it into equivalent Python, Node.js, or Java code. The parser handles the most common curl flags — HTTP method (-X), headers (-H), request body (-d), and basic authentication (-u) — generating correct requests using each language's standard HTTP library. Switch between language tabs to compare the generated code and copy any version with one click.
What Is the cURL to Code Converter?
cURL to Code Converter is a free, browser-based developer tool that translates curl commands into equivalent code in Python, Node.js, and Java. It parses HTTP method, headers, request body, and basic authentication flags to generate correct, runnable code using each language's standard HTTP library. No data is sent to any server — all parsing happens locally in your browser.
This tool converts basic curl commands. It handles -X (method), -H (headers), -d (body), and -u (basic auth). It does not support cookies, multipart file uploads, proxy settings, SSL certificates, or redirect following. For complex curl commands, you'll need to manually translate those parts. Unsupported flags are clearly flagged with a warning.
Supported curl Flags
| Flag | Example | Supported |
|---|---|---|
-X / --request | -X POST | ✓ Yes |
-H / --header | -H "Content-Type: application/json" | ✓ Yes |
-d / --data | -d '{"key":"val"}' | ✓ Yes |
-u / --user | -u admin:pass123 | ✓ Yes |
--cookie / -b | --cookie "session=abc" | ✗ No |
-F / --form | -F "file=@photo.jpg" | ✗ No |
--proxy / -x | -x http://proxy:8080 | ✗ No |
-k / --insecure | -k | ✗ No |
-L / --location | -L | ✗ No |
Key Features
- Multi-Language Output: Python (requests), Node.js (fetch), and Java (HttpClient) — switch between tabs instantly.
- Auto-Detection: JSON bodies auto-detect and use the cleanest syntax (
json=in Python,JSON.stringify()in Node). - Basic Auth Support:
-u user:passtranslates to HTTPBasicAuth in Python, btoa+Authorization header in Node, Base64 in Java. - Unsupported Flag Warnings: If your curl uses cookies, multipart forms, or proxy flags, you'll see a clear warning — not silent ignorance.
📋 When to Use the cURL to Code Converter
API Development: Testing endpoints with curl, then converting working commands to application code.
CI/CD Pipelines: Turning a curl health check into a Python script for monitoring.
Documentation: Converting API docs from curl examples to multi-language code snippets.
Onboarding: Helping new team members translate curl commands without looking up HTTP library syntax.
⚙️ How the cURL to Code Converter Works
The parser tokenizes your curl command into flags and arguments using a regex-based tokenizer that respects single and double quotes. It identifies -X for HTTP method, -H (repeatable) for headers, -d/--data for request body, -u for basic auth credentials, and the positional URL. Auto-detection applies: if -X is omitted and a body is present, the method defaults to POST. If the body parses as valid JSON, Python uses json= (auto-serialize) and Node wraps it in JSON.stringify(). The parsed data is then mapped to each language's idiomatic HTTP library — Python requests, Node built-in fetch (Node 18+), and Java java.net.http.HttpClient (Java 11+). Everything runs in your browser; no data is ever sent to a server.
Python Requests Code
The Python output uses the requests library — the de facto standard for HTTP in Python. If the curl body is JSON, the generator uses json= for clean auto-serialization. For raw text bodies, data= is used. Basic auth via -u produces HTTPBasicAuth.
# pip install requests
import requests
url = "https://httpbin.org/post"
headers = {"Content-Type": "application/json"}
response = requests.post(url, headers=headers, json={"name": "test"})
print(response.status_code)
print(response.text)Node.js Fetch Code
The Node.js output uses the built-in fetch API, available globally in Node.js 18+. No npm install or import required.
// Node.js 18+ (built-in fetch, no import needed)
const url = "https://httpbin.org/post";
const options = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "test" })
};
const response = await fetch(url, options);
console.log(response.status);
console.log(await response.text());Java HttpClient Code
The Java output uses java.net.http.HttpClient from the Java 11+ standard library — zero external dependencies.
// Java 11+ (stdlib HttpClient, zero dependencies)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://httpbin.org/post"))
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString("{\"name\":\"test\"}"))
.build();
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());How to Use the cURL to Code Converter
- Paste your curl command into the input field above.
- Click Convert to Code. The tool parses method, headers, body, and auth.
- Review the output in all three tabs — Python, Node.js, and Java.
- Copy the code for your chosen language using the Copy button.
Frequently Asked Questions
How do I convert a curl POST with JSON body to Python?
Paste your curl command and select the Python tab. The tool auto-detects JSON bodies and uses requests.post(url, json={...}) for clean syntax. If the body is raw text, it uses data= instead.
What Node.js library does this use: fetch or axios?
Built-in fetch API (Node.js 18+). No npm install or import needed. Fetch is globally available in all modern Node.js versions.
Does the Java output use Apache HttpClient or java.net.http?
Standard java.net.http.HttpClient (Java 11+). Zero external dependencies. It's part of the Java standard library since JDK 11.
How do I add Basic Auth (curl -u) in Python requests?
The tool generates HTTPBasicAuth(user, pass). Just add -u user:pass to your curl command and Convert — the auth code is auto-generated.
Why is my --cookie flag not working?
Cookies (--cookie, -b, -c) are not supported. To include cookies, add them as a header: -H "Cookie: key=value".
Can I convert curl commands with file upload (-F)?
Multipart file uploads (-F, --form) are not supported yet. The tool focuses on JSON/raw body requests.
Does this tool work offline?
Yes — all parsing and code generation happens entirely in your browser. No server processing, no data sent anywhere.
Is the generated code production-ready?
The code is syntactically correct and runnable, but add error handling (try-catch, response status checking, timeouts) before production use.
Does the Python output require any pip install?
Yes, the Python code uses the requests library. If not already installed, run pip install requests. The generated code includes this as a comment.