cURL to Fetch Converter (JavaScript & Node)
Convert cURL to Fetch API syntax instantly. Parse HTTP headers, auth tokens, cookies, and JSON body payloads into modern async/await JavaScript code.
Convert cURL to Fetch API syntax instantly. Parse HTTP headers, auth tokens, cookies, and JSON body payloads into modern async/await JavaScript code.
Convert cURL to Fetch API syntax instantly. Parse HTTP headers, auth tokens, cookies, and JSON body payloads into modern async/await JavaScript code.
Raw command-line invocation starting with 'curl'. Supports multiline backslash line continuations, single and double shell quote escaping, and standard POSIX flag conventions.
Determines code emission formatting: standard browser ES2022 async/await, strongly typed TypeScript with ApiResponse generics, Node.js 18+ server syntax with AbortSignal, Next.js App Router with caching tags, or Axios client syntax.
HTTP request verb. When -X is omitted, cURL automatically defaults to GET unless request body flags (-d, --data, -F) are present, which implicitly switch the default method to POST.
Custom request metadata headers. Browser fetch implementations enforce forbidden header restrictions (e.g. Host, Content-Length, Cookie cannot be manually overwritten via Headers API for security isolation).
Data payload transferred in POST, PUT, or PATCH requests. Parsed dynamically into JSON.stringify() for JSON strings, URLSearchParams() for application/x-www-form-urlencoded, or FormData() for multipart uploads.
Authentication credentials. cURL -u user:pass is synthesized into 'Authorization: Basic <base64>', while -H 'Authorization: Bearer <token>' is extracted into structured variables with optional redaction masking.
Unlike cURL CLI (which prints error status codes) or Axios (which rejects promises on 4xx/5xx responses), the native JavaScript Fetch API only rejects its promise when a genuine network failure occurs or CORS blocks the request. A 404 Not Found, 401 Unauthorized, or 500 Internal Server Error still resolves successfully. You must explicitly evaluate 'if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);' before calling response.json() or response.text().
When converting cURL -F ('--form') file upload commands to Fetch, do NOT set the 'Content-Type: multipart/form-data' header manually. Doing so strips the dynamic boundary parameter (e.g. 'boundary=----WebKitFormBoundary...') that the browser automatically generates to delimit payload segments. Simply pass the FormData instance directly to the body option, and the browser will automatically compute the correct Content-Type with boundary delimiters.
In cURL, passing -d without an explicit Content-Type header defaults to 'application/x-www-form-urlencoded', not JSON. Many developers mistakenly wrap -d 'key=val&foo=bar' inside JSON.stringify(). Always inspect whether your payload is key-value pairs (which should use 'new URLSearchParams({ key: 'val', foo: 'bar' })') or valid JSON (which requires 'JSON.stringify(data)' and an explicit 'Content-Type: application/json' header).
Terminal cURL can forge any HTTP header, including 'Cookie', 'User-Agent', 'Referer', and 'Host'. However, in browser JavaScript Fetch, the W3C Fetch specification designates these as 'Forbidden Header Names' to prevent cross-site request forgery and cookie theft. Browser fetch will silently discard manual 'Cookie' headers; instead, pass 'credentials: "include"' (or 'same-origin') to permit the browser's cookie jar to attach session tokens automatically.
cURL is a command-line tool exempt from browser Same-Origin Policy (SOP). When running fetch() in client-side browser JavaScript against a third-party API that does not return 'Access-Control-Allow-Origin: *' headers, the browser blocks the response. To resolve this, call the API from a backend server (Node.js, Next.js Route Handler, or Cloudflare Worker) where CORS does not apply, or configure proper CORS headers on the destination server.
This error occurs when calling 'await response.json()' on an API endpoint that returned an empty body (e.g., 204 No Content), an HTML error page (e.g., Cloudflare 502 Bad Gateway), or plain text. Always verify 'response.headers.get('content-type')?.includes('application/json')' before calling response.json(), or check 'const text = await response.text()' with safe JSON.parse wrapping.
This happens when 'Content-Type: multipart/form-data' is explicitly declared in fetch headers. When using FormData(), remove the 'Content-Type' header entirely from the headers object. The browser or Node.js runtime will automatically inject 'multipart/form-data; boundary=----WebKitFormBoundary...' with the exact calculated multipart boundary.
When copying multiline cURL commands from bash scripts or developer documentation, trailing spaces after the backslash character ('\ ') cause bash and parsers to treat the newline as literal text rather than an argument continuation. Our parser automatically normalizes '\ ' and '\ ' tokens, stripping whitespace and merging multiline terminal snippets into a unified argument sequence.
To convert a cURL command to Fetch, parse the target URL from the command line, map -X to the fetch 'method' property (GET, POST, PUT, DELETE), convert each -H argument into key-value pairs inside the 'headers' object, format -d or --data payloads into 'JSON.stringify(payload)' or 'new URLSearchParams(payload)' inside the 'body' property, and wrap the call in an 'async/await' function with 'const response = await fetch(url, options)'.
cURL operates as a raw HTTP client without browser security sandboxing, so it ignores Same-Origin Policy and Cross-Origin Resource Sharing (CORS) rules. Modern web browsers enforce CORS to prevent unauthorized web applications from reading sensitive cross-origin data. If the target server does not send 'Access-Control-Allow-Origin' matching your web app's origin, the browser aborts the fetch call. To fix this, proxy the request through a backend server or serverless API route.
In cURL, '-u username:password' sends HTTP Basic Authentication. In modern browser JavaScript Fetch, encode the credentials using Base64 via 'btoa("username:password")' and attach it as 'headers: { Authorization: `Basic ${btoa("username:password")}` }'. In Node.js, use 'Buffer.from("username:password").toString("base64")' to achieve the identical standard header value.
In browser JavaScript, the 'Cookie' header is a forbidden header name and cannot be set programmatically in fetch() headers due to security standards. To send cookies stored in the browser for the target domain, set 'credentials: "include"' in the fetch options object. In Node.js server environments (where browser security restrictions do not apply), you can pass 'Cookie: session_id=xyz' directly inside the headers object.
In cURL, '-d' and '--data-raw' transmit the exact string provided, defaulting to Content-Type 'application/x-www-form-urlencoded' unless overridden by -H. In Fetch, if the data is JSON, you must serialize it via JSON.stringify() with 'Content-Type: application/json'. If the cURL uses '--data-urlencode', parameter values are URL-encoded before sending, which in Fetch is natively handled by passing key-value pairs into 'new URLSearchParams({ key: value }).toString()'.
Validate XML sitemaps and sitemap index files instantly. Check 50k URL limits, W3C Datetime syntax, hreflang tags, media schemas, and Google Search Console errors.
Preview Google SERP desktop and mobile search snippets with accurate pixel width truncation, rich snippet schema badges, sitelinks, and live CTR scoring.
Generate multi-point CSS mesh gradients, animated backgrounds, and SVG color meshes. Customize control points, grain texture, and copy CSS or Tailwind code.
Build, validate, and batch generate Google Analytics GA4 campaign tracking links with our free UTM builder. Clean URLs, parse existing tags, and export QR codes.
Format, beautify, validate, and repair dirty JSON online instantly. Clean syntax errors, fix unquoted keys, minify, and inspect tree nodes with zero server uploads.
Encode and decode Base64 strings or binary files instantly. Supports URL-safe base64url, UTF-8 unicode, MIME line wrapping, Data URLs, and live error repair.