cURL to JavaScript fetch() Converter
Paste a curl command and get a JavaScript fetch() equivalent. Handles method, headers, JSON and form bodies, and HTTP Basic auth (-u). Great for copying API docs into code.
const res = await fetch("https://api.example.com/users", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer sk_test_abc",
},
body: "{\"name\":\"Ada\",\"role\":\"admin\"}",
});
const data = await res.json();How to use
- 1Paste your curl command
Copy directly from API docs, terminal history, or a Postman export. Line-continuation backslashes are handled.
- 2Read the generated fetch()
Method, headers, and body are all mapped. JSON bodies are parsed and re-serialized so you can edit the object in code.
- 3Drop it into your app
Works in browser fetch, Node 18+ native fetch, and (with tiny tweaks) axios.
Examples
curl -H "Authorization: Bearer abc123" https://api.example.com/me
fetch('https://api.example.com/me', {
method: 'GET',
headers: {
'Authorization': 'Bearer abc123',
},
});curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name":"Alex","role":"admin"}'fetch('https://api.example.com/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Alex',
role: 'admin',
}),
});curl -u alice:secret123 https://api.example.com/private
fetch('https://api.example.com/private', {
method: 'GET',
headers: {
'Authorization': 'Basic YWxpY2U6c2VjcmV0MTIz',
},
});curl -X POST https://api.example.com/login -d "user=alice&pass=x"
fetch('https://api.example.com/login', {
method: 'POST',
body: 'user=alice&pass=x',
});Frequently asked
-X/--request, -H/--header, -d/--data/--data-raw/--data-binary/--data-urlencode, -u/--user (Basic auth), --url, and the positional URL. Flags that don't map to fetch (-k, -L, --compressed, -s, -v, -o) are silently ignored.
Yes — line-continuation backslashes are handled, so you can paste directly from a `curl` example in docs.
The output is standard `fetch()` compatible with modern browsers and Node 18+. `Authorization: Basic …` is generated for `-u user:pass`; other auth schemes need to be added by hand.
The output uses the fetch standard, which works in Node 18+ natively without node-fetch. For axios, the shape is similar — the URL and options map directly.
JSON in -d is parsed and re-serialized so the fetch body is JSON.stringify(...) with the parsed object literal, not a raw string. Easier to edit in your code afterwards.
Related tools
- HTTP Headers ReferenceEvery common HTTP header explained, grouped by purpose. Searchable by name or ke
- HTTP Status CodesEvery HTTP status code you need to know, grouped by category, with plain-English
- JSON FormatterFormat, validate, and minify JSON in your browser. See parse errors with line/co
- .env File ParserParse a .env file and see it as a JSON object. Handles comments, quoted values,
- Base ConverterConvert numbers between binary, octal, decimal, and hexadecimal. Supports huge n
- Credit Card ValidatorValidate credit card numbers with the Luhn algorithm and detect the brand: Visa,