cURL to Fetch Converter

Convert cURL commands to JavaScript fetch API calls

About This Tool

cURL is the de facto command-line HTTP client; the Fetch API is its in-browser equivalent. Translating between them means converting flag-based options to a configuration object — `-X` becomes `method`, `-H` becomes `headers`, `-d` becomes `body`, `-u` becomes a basic-auth Authorization header.

This converter parses common cURL invocations (including multi-line continuations and quoted JSON) and emits an equivalent fetch() call.

cURL was first released in 1997 by Daniel Stenberg and has accumulated more than 200 command-line flags covering authentication, TLS configuration, proxy handling, retry logic, and protocol-level details. The Fetch API, standardized in the WHATWG Fetch Living Standard around 2015, is a much simpler surface — a function call with a URL and an options object. Many cURL flags map cleanly: `-X POST` → `method: 'POST'`, `-H 'Content-Type: application/json'` → `headers: { 'Content-Type': 'application/json' }`, `-d '{...}'` → `body: '{...}'`. Others have no equivalent because the browser handles them automatically (`--compressed`, `--tcp-fastopen`) or because they require capabilities the Fetch sandbox doesn't provide (`--cacert`, `--resolve`, `--interface`).

A worked example: `curl -X POST https://api.example.com/users -H 'Content-Type: application/json' -H 'Authorization: Bearer abc123' -d '{"name":"Alice"}'` translates to `fetch('https://api.example.com/users', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer abc123' }, body: JSON.stringify({ name: 'Alice' }) })`. Notice the body is stringified — fetch sends body as-is, so JSON must be serialized first. cURL would send the string literal, which works because JSON.stringify of an already-stringified JSON produces a quoted string.

Limitations: the converter handles common patterns but not edge cases. cURL's `--data-urlencode` requires URL-encoding before submission; the converter applies encodeURIComponent. Multipart uploads (`-F`) need FormData and assume browser-side File objects, which won't work directly in Node fetch without a polyfill. cURL's `-G` (force GET with data as query string) translates by appending the data to the URL. SSL certificate flags, NTLM authentication, and proxy configurations have no fetch equivalent and are silently dropped or flagged as untranslatable. CORS is the most common runtime problem: cURL ignores it; browser fetch enforces it. A working cURL command can fail with the exact same fetch translation if the server doesn't return appropriate CORS headers.

The about text and FAQ on this page were drafted with AI assistance and reviewed by a member of the Coherence Daddy team before publishing. See our Content Policy for editorial standards.

Frequently Asked Questions