ZenovayTools

cURL to Fetch Converter

Convert cURL commands to JavaScript fetch() API code. Parses curl flags: -X (method), -H (headers), -d/--data (body), --json, -u (basic auth), --data-urlencode, -G (GET with data), and more.

Examples:

How to Use cURL to Fetch Converter

  1. 1Paste your cURL command into the input field.
  2. 2The tool parses all curl flags and options automatically.
  3. 3JavaScript fetch() code is generated with equivalent headers, method, and body.
  4. 4Copy the fetch code directly into your JavaScript project.
Zenovay

Track your website performance

Real-time analytics, session replay, heatmaps, and AI insights. 2-minute setup, privacy-first.

Try Zenovay Analytics — Free

Frequently Asked Questions

What curl flags does this converter support?
-X / --request: HTTP method (GET, POST, PUT, PATCH, DELETE, etc.). -H / --header: Add request header (multiple supported). -d / --data / --data-raw: Request body. --data-urlencode: URL-encoded data. --json: Send JSON body (sets Content-Type automatically). -u / --user: Basic authentication (user:password). -L / --location: Follow redirects (included as comment). --compressed: Accept compressed responses. -b / --cookie: Cookie header. --form / -F: Form data (multipart). -k / --insecure: Skip SSL verification (noted as comment).
How does -d/--data work in curl vs fetch?
In curl, -d sends data as the request body with Content-Type: application/x-www-form-urlencoded by default. Multiple -d flags concatenate data with &. In fetch, the equivalent is body: "key=value&other=val" with a matching Content-Type header. If you use --json in curl (curl 7.82+), it sets Content-Type: application/json and sends JSON body — this maps to body: JSON.stringify(data) in fetch. If your curl already includes -H "Content-Type: application/json", the converter detects this and formats the body accordingly.
How is basic auth (-u user:pass) converted?
curl -u username:password sends HTTP Basic Authentication. In JavaScript fetch, this maps to an Authorization header: Authorization: Basic {base64(username:password)}. The converter generates btoa("username:password") in the fetch code. Note: embedding credentials in client-side code is insecure — for production use, pass credentials server-side or use environment variables.
What about cookies (-b/--cookie)?
curl -b "name=value; other=val" sends cookies as a Cookie header, which directly maps to a fetch header: "Cookie": "name=value; other=val". However, note that browser-based fetch cannot set the Cookie header for cross-origin requests (CORS restrictions). This is a security feature — cookies for cross-origin requests are handled automatically by the browser based on the cookie's domain and SameSite settings.
Why might the generated fetch code need manual adjustments?
Curl has many flags that don't have direct fetch equivalents: --retry (no native retry in fetch), --max-time/--connect-timeout (requires AbortController with setTimeout), --proxy (not supported in browser fetch), --cert/--key (TLS client certificates, not in browser fetch). The converter handles the most common flags. For edge cases, you may need to wrap fetch with retry logic or use a Node.js HTTP library like axios or got which supports more options.