🌐 cURL Command to Code Converter
A curl converter that turns a pasted command into Fetch, Axios and Python requests code, parsed in your browser with nothing sent anywhere.
Converted Code (FETCH)
const response = await fetch('https://api.example.com/v1/users', {
method: 'POST',
headers: {
"Authorization": "Bearer token123",
"Content-Type": "application/json"
},
body: JSON.stringify({"name": "Alice", "role": "admin"}),
});
const data = await response.json();
console.log(data);What cURL Command to Code Converter Does
This tool parses a pasted curl command and generates three targets: a Fetch API call, an Axios request, and a Python script using the requests library. Parsing happens entirely in the browser as you type; nothing is sent anywhere and no command is stored.
curl commands are genuinely awkward to parse correctly. Flags can appear in any order, a JSON body can contain its own quotes and escapes, and a header value has to survive being pulled out of a quoted argument intact. This tool walks the command as a real shell would: it tokenizes the text first, tracking whether it is inside single quotes, double quotes, or reading a backslash escape, and only then reads the resulting argument list for flags. A header or data flag placed before the URL — which is exactly how commands copied from a browser's network panel are usually ordered — still resolves correctly, because the whole list is scanned rather than matched at a fixed position.
It also makes one inference explicit. If the command has no -X or --request but does have a body (-d, --data or --data-raw), the generated code uses POST; curl does the same thing internally. The curl manual states it directly: -d "is done with the POST method in the same way that a browser does when a user has filled in an HTML form and presses the submit button." If neither a method flag nor a body is present, the output defaults to GET.
How to Use cURL Command to Code Converter
- Paste your cURL command into the editor
- Select target output language (JavaScript Fetch, Axios, or Python Requests)
- Review the clean converted code and click Copy Code
Argument Patterns This Tool Recognizes
Six patterns are matched by walking the tokenized argument list. Anything not on this list is not read.
| Pattern | Example | What it sets |
|---|---|---|
| -X METHOD or --request METHOD | -X DELETE | The HTTP method, used exactly as typed |
| Glued -X shorthand | -XPOST | Same as above, read as -X plus everything after it in the same token |
| -H HEADER or --header HEADER | -H "Accept: application/json" | One header, split at the first colon, both sides trimmed |
| -d, --data or --data-raw VALUE (first one only) | -d '{"name": "Alice"}' | The request body; also triggers POST if no method flag was given |
| --url URL | --url "https://api.example.com/x" | The request URL |
| A bare token starting with http:// or https:// | https://api.example.com/x with no preceding flag | The request URL, if --url has not already set one |
Same curl Flag, Three Different Outputs
What each recognized flag becomes in each target, verified against the tool's own output.
| curl input | Fetch (JavaScript) | Axios (JavaScript) | Python (Requests) |
|---|---|---|---|
| -X POST or -XPOST | method: 'POST' — kept exactly as typed | method: 'post' — lowercased in the config object | Lowercased and used to pick the call: requests.post(...) |
| -H "Key: Value" (repeatable) | A headers object as the second fetch() argument | A headers object inside the config passed to axios() | A headers dict, passed as headers=headers |
| -d '<body>' | body: JSON.stringify(<body>) in the options object | data: <body>, inserted as-is, not re-stringified | payload = <body>, passed as json=payload |
| URL (from --url or a bare token) | First argument to fetch('URL', …) | url: 'URL' inside the config object | First argument to requests.<method>('URL', …) |
Flags This Tool Does Not Parse
Verified directly against the parsing code. Each of these is silently dropped, or, for a repeated -d, only the first is kept — there is no warning either way.
| Flag | What it does in curl | What happens here |
|---|---|---|
| -F or --form (multipart/form-data) | Uploads a file, or sends a multi-part field | Dropped along with its value; the generated request has no body at all |
| -u or --user (Basic Authentication) | Sends credentials via an Authorization header | Dropped; the generated code makes an unauthenticated request with no indication anything was lost |
| -b or --cookie | Attaches a Cookie header | Dropped the same way |
| --compressed | Requests a compressed response | Ignored harmlessly — it takes no value, so it does not disturb the flags around it |
| A second or later -d, --data or --data-raw | curl concatenates repeated -d values with an & | Only the first occurrence is kept; the rest are dropped silently |
| A glued header, e.g. -H"Accept: json" | Not standard curl syntax for -H, but the -X glued form exists | Not recognized — only -X has a glued form here; -H and -d both need a separating space |
How to Read Your Result
Flag order does not matter
A command copied from a browser's "Copy as cURL" feature usually lists -H and -d before the URL. Verified against curl -H "Content-Type: application/json" -d '{"name": "Alice"}' https://api.example.com/v1/users: the tool still finds the URL, still builds the Content-Type header, and still infers POST from the body. A parser that only checks fixed positions in the string — URL first, flags after — misses all three when the order is reversed.
Method casing differs by target, verified
Fetch keeps the method exactly as it appears in the command: -X POST produces method: 'POST'. Axios and Python requests both lowercase it before use — the same command produces method: 'post' in the Axios config, and Python picks requests.post(...) as the function to call. If the curl command already used lowercase, all three targets agree from the start; the difference only becomes visible on commands written in uppercase, which is the common convention shown in curl's own examples.
The glued -XPOST form is a separate rule from -X POST
curl accepts both -X POST, with the method as its own argument, and -XPOST, glued to the flag. This tool matches the glued form with a dedicated pattern that reads everything after -X inside the same token: curl -XPOST https://api.example.com/v1/login -d '{"user": "bob"}' correctly becomes requests.post(...) in the Python target. That pattern is specific to -X. A glued header or data flag with no space, such as -H"Accept: json", is not recognized and is dropped.
A quoted body survives intact, escaped quotes and all
A JSON body that contains a quotation mark inside a string value needs that quote escaped within the outer quotes. A parser that just grabs the text between the first pair of quotes after -d treats the escaped quote as the closing one and truncates there — verified against such a body, a naive quote-to-quote match captured only the first two characters and silently dropped the rest of the JSON. This tool instead walks the command character by character, tracking whether it is inside single quotes, double quotes, or reading a backslash escape, so the full body reaches the output whichever quoting style it used.
Limitations & Accuracy Notes
- Only three output targets exist: a Fetch call, an Axios call, and Python using requests. There is no PHP, Go, Java, HTTPie or raw HTTP target.
- -F and --form (multipart form data, including file uploads) are not recognized. The flag and its value are dropped entirely and the generated request ends up with no body.
- -u and --user (HTTP Basic Authentication) are not recognized. The credentials are dropped and the generated code makes an unauthenticated request, with nothing in the output to flag that authentication was lost.
- -b and --cookie are dropped the same way; no Cookie header appears in any target.
- Only the first -d, --data or --data-raw flag is used. curl itself concatenates repeated -d flags with an &; this tool keeps just the first one.
- A header needs a space after -H or --header. The glued shorthand that works for -X (-XPOST) does not exist for headers or data flags.
- The body is inserted into the target language as literal source text, not re-parsed and re-serialized. That produces two concrete failure modes: a body that is not valid JSON — form-encoded key=value pairs, curl's own default for -d — becomes a syntax error in every target, and a JSON body containing true, false or null produces invalid Python, since Python requires True, False and None instead.
- curl's own default content type for -d is application/x-www-form-urlencoded, not JSON. This tool always builds a JSON body regardless of what Content-Type header, if any, was actually set — correct for the common case of testing a JSON API, wrong for a plain form post.
- The tool does not validate that the URL is reachable or that the method string is one a real server accepts; both are passed straight through.
Frequently Asked Questions
What is cURL?
Does this tool support custom headers and JSON payloads?
Is my curl command sent anywhere?
Should I remove anything before sharing a converted command?
What does -X do, and when do I not need it?
What is the difference between -d and --data-raw?
Why does my converted request get a different response?
Does -k or --insecure matter?
References & Further Reading
- curl.se — curl Manual (-X, -H, -d and every flag) — Primary source for what each flag does, including the exact wording on -d defaulting to POST, quoted above
- MDN — Fetch API — Reference for the fetch() call generated by the JavaScript (Fetch) target
- Python requests — Quickstart — Reference for the requests.post(...) / json= behavior used by the Python target
- RFC 9110 — HTTP Semantics — Current IETF standard defining GET, POST, PUT, DELETE and the other methods set by -X; obsoletes RFC 7231