SyntaxDock guide

How to Convert Fetch to cURL: Examples and Limitations

Convert static Fetch calls to cURL with GET, JSON, URLSearchParams, and FormData examples. Understand redirects, credentials, CORS, and conversion limits.

Convert Fetch source without executing JavaScript

The Fetch to cURL Converter turns one supported, statically resolvable HTTP or HTTPS Fetch call into cURL text. Paste the source, choose Convert to cURL, and inspect the output and diagnostics before copying. SyntaxDock parses the source as data and never executes supplied JavaScript, generated cURL, or the represented request.

Literal strings, no-substitution template literals, and supported earlier immutable const bindings can describe the request. Conversion cannot reconstruct runtime application state or a browser session.

Start with a simple GET

fetch("https://example.test/users")

Generated cURL:

curl \
  --location \
  'https://example.test/users'

GET is the default method. Fetch follows redirects by default, so the converter emits --location. This example has no diagnostics: Method GET, Headers 0, Body No, Warnings 0.

Send a JSON POST with an explicit Content-Type

fetch("https://example.test/users", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ name: "Ada" }),
})

Generated cURL:

curl \
  --location \
  --header 'Content-Type: application/json' \
  --data-raw '{"name":"Ada"}' \
  'https://example.test/users'

The converter serializes this supported static object as compact JSON. The body option --data-raw implies POST, so a separate --request option is unnecessary here. This example has no diagnostics: Method POST, Headers 1, Body Yes, Warnings 0.

JSON.stringify creates a string; it does not set the request's Content-Type. Without the explicit header, this converter supplies the string body's effective text/plain;charset=UTF-8 type. Set application/json when that is what the recipient expects.

Convert URLSearchParams

fetch("https://example.test/search", {
  method: "POST",
  body: new URLSearchParams([["q", "two words"], ["tag", "api"], ["tag", "json"]]),
})

Generated cURL:

curl \
  --location \
  --header 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' \
  --data-raw 'q=two+words&tag=api&tag=json' \
  'https://example.test/search'

The space becomes +, and repeated tag parameters retain their order. These parameters remain a POST body; the converter does not move them into the URL. The effective form Content-Type is included. This example has no diagnostics: Method POST, Headers 1, Body Yes, Warnings 0.

Convert text-only FormData

const formData = new FormData();
formData.append("name", "Ada");
formData.append("role", "reader");
fetch("https://example.test/submit", { method: "POST", body: formData });

Generated cURL:

curl \
  --location \
  --form-string 'name=Ada' \
  --form-string 'role=reader' \
  'https://example.test/submit'

The supported pattern uses a preceding top-level declaration and ordered two-string append calls. cURL creates the multipart boundary. Do not supply a manual multipart Content-Type: the converter rejects it because it cannot match cURL's generated boundary. File and Blob fields and advanced FormData mutations are unsupported. This example has no diagnostics: Method POST, Headers 0, Body Yes, Warnings 0.

Understand redirects, cookies, credentials, headers, and CORS

A generated command describes a supported request, not the complete browser environment. Browser Fetch applies CORS, preflight, header, and cookie rules that command-line cURL does not reproduce. Successful conversion does not prove the request will succeed when run elsewhere.

Fetch options and cURL compatibility
Fetch inputConverter behavior
Redirect omitted or "follow"Emits --location. Browser and cURL redirect behavior can still differ.
redirect: "manual"Omits redirect following; the simple GET becomes a one-line command.
redirect: "error"Omits following and warns with fetch.curl.option_not_equivalent. This does not reproduce Fetch's error behavior.
Explicit credentials: "include" or "same-origin"Warns with fetch.curl.credentials_not_equivalent; no browser cookie values are available to transfer.
Credentials omitted or "omit"No credentials warning. Browser Fetch defaults to same-origin credentials; absence of a warning does not establish browser-session equivalence.
Explicit Cookie or other browser-controlled headerOmits the header and warns with fetch.curl.browser_header_ignored. SyntaxDock also omits headers such as Host, Content-Length, Origin, Referer, and User-Agent under its compatibility policy.
mode: "cors" and supported browser-only optionsWarns with fetch.curl.option_not_equivalent; cURL has no equivalent browser CORS mode.
Supported Authorization headerPreserves the supplied value. Local conversion does not automatically redact credentials.

Recognize unsupported dynamic JavaScript

An unresolved URL is rejected rather than guessed:

fetch(apiUrl)

Error — fetch.url.dynamic_unsupported: The Fetch URL cannot be resolved statically. Line 1, column 7. No cURL output is generated.

An earlier immutable binding such as const apiUrl = "https://example.test/users" followed by fetch(apiUrl) is supported and produces the same result as the simple GET.

Runtime body construction is also rejected; the converter never calls makePayload:

fetch("https://example.test/users", {
  method: "POST",
  body: JSON.stringify(makePayload()),
})

Error — fetch.body.unsupported: This Fetch body form is not supported. Line 3, column 24. No cURL output is generated.

Replace runtime construction with supported static data, as in the JSON POST example. Template substitutions, runtime property reads, arbitrary functions, mutable bindings, and multiple Fetch calls cannot be reconstructed. Their diagnostics depend on the unsupported construct.

Review conversion limits and sensitive request data

Input is limited to 1 MiB and generated cURL to 2 MiB, measured as UTF-8 bytes. Oversized content is rejected without truncation. GET and HEAD bodies are rejected. NUL characters cannot be represented in cURL arguments.

Output uses POSIX single-quoted shell arguments, with embedded single quotes escaped. It is not a PowerShell or Windows shell representation. Review the generated text before using it in a separate terminal; SyntaxDock itself never runs it.

Your source and generated command stay local in this browser. SyntaxDock does not upload or persist request data or send it to the represented endpoint. Supplied authorization headers, URLs, and body values can remain in output: remove sensitive values before sharing source, copied commands, or screenshots. The examples above use synthetic data and contain no credentials.

Convert cURL back to Fetch

For the reverse workflow, use the cURL to Fetch Converter and read the cURL to Fetch guide. Both directions support a documented static subset. A round trip need not preserve original formatting, constructors, browser authentication state, or every networking option. Review the request semantics and diagnostics in either direction.