API & HTTP
Fetch to cURL Converter
Convert browser Fetch calls into cURL commands.
Fetch to cURL Converter workspace
Input
Preparing tool…
Result
Preparing tool…
How it works
Documentation
About Fetch to cURL
Convert one statically resolvable HTTP or HTTPS Fetch call into a deterministic command-line cURL command. SyntaxDock parses JavaScript but never executes it. The represented request is never sent.
How to convert
Paste a supported Fetch call, choose Convert to cURL, and copy the generated command. SyntaxDock generates cURL text but never runs it.
Supported Fetch syntax
The converter accepts one top-level fetch(...) call, optionally preceded by await or assigned to a top-level const. It supports a static HTTP or HTTPS URL and a static options object containing supported method, headers, body, credentials, redirect, referrer, and browser-only option values.
Static JavaScript only
String literals, no-substitution template literals, selected literal arrays and objects, and earlier immutable const bindings are resolved as data. Functions, getters, computed properties, spreads, mutable variables, runtime branches, and shadowed browser globals are rejected instead of executed or guessed.
Request methods
GET is the default. HEAD and standard HTTP methods are supported, along with safe custom HTTP tokens. CONNECT, TRACE, and TRACK are rejected. A GET or HEAD body is rejected because browser Fetch does not permit it.
Headers
Static object headers, ordered header tuples, and a narrowly supported new Headers(...) wrapper can be converted. Meaningful duplicate tuple headers retain their order. Browser-controlled headers such as Cookie, Host, Content-Length, Origin, Referer, User-Agent, Proxy-*, and Sec-* are omitted with warnings.
String and JSON bodies
Static string bodies become --data-raw. A supported JSON.stringify(...) expression is serialized as compact JSON data. Fetch-effective Content-Type headers are included when the browser would supply one and you did not set one explicitly.
URLSearchParams
A static new URLSearchParams(...) string, record, or ordered tuple list becomes URL-encoded request data. The generated cURL includes Fetch's effective application/x-www-form-urlencoded;charset=UTF-8 Content-Type when needed.
FormData
Text-only FormData uses a preceding top-level const formData = new FormData() followed by ordered two-string formData.append(name, value) calls. Fields render with --form-string, while cURL creates the multipart boundary. Files, Blobs, advanced mutations, and a manually supplied multipart boundary are rejected.
Credentials and cookies
Fetch credentials modes describe browser-managed cookies and authentication state; they do not contain transferable cookie values. Explicit same-origin or include intent therefore produces a warning, and the converter never invents a Cookie header.
Redirects
Fetch follows redirects by default, so the generated command includes --location. A manual redirect mode omits redirect following. Fetch redirect: "error" has no exact cURL equivalent and produces a warning.
Referrer
An absolute static HTTP or HTTPS referrer becomes cURL's --referer option. Empty referrers are represented by omitting it. Browser-derived or relative referrers are omitted with a warning because cURL cannot reproduce the browser context.
Browser-only Fetch options
Options such as mode, cache, referrerPolicy, integrity, keepalive, signal, and priority can affect browser behavior but have no direct cURL equivalent. The converter reports these differences without exposing their values in diagnostics.
CORS differences
Browser Fetch is subject to CORS and forbidden-header rules. cURL is not a browser and does not enforce the same origin policy, preflight behavior, or browser cookie controls. Browser Fetch and command-line cURL are not equivalent in every case.
Shell quoting and output format
Every generated value is rendered as a POSIX single-quoted shell argument with embedded quotes escaped safely. Options appear in a stable method, redirect, referrer, header, body, and URL order. NUL characters cannot be represented and stop conversion without partial output.
Unsupported dynamic JavaScript
Dynamic URLs, function calls, property reads, template substitutions, multiple Fetch calls, later mutations, and unsupported constructor patterns stop conversion with a diagnostic. Rewrite the request as static data if you want to convert it.
Privacy
Your Fetch code and generated cURL stay local in this browser. SyntaxDock does not upload, store, execute, or send the URL, headers, credentials, body, FormData fields, or generated command to a represented endpoint.
Input is limited to 1 MiB and generated cURL output to 2 MiB. Oversize input or output is rejected without truncation.
FAQ
Why did conversion stop? Check for dynamic JavaScript, multiple Fetch calls, a mutated value, unsupported body data, or a browser global that has been redefined. Why was a header omitted? Browsers control some headers, so the original Fetch call cannot reliably set them. Does this run my request? No. It only produces inert cURL text locally.
Related tools
Use cURL to Fetch Converter for the reverse conversion, JSONPath Tester to inspect JSON responses, and JSON Diff to compare JSON documents.