SyntaxDock guide
How to Convert cURL to Fetch
Translate a cURL request into a browser Fetch call while preserving its method, headers, and body.
Convert request text without executing it
Paste a supported cURL command into the cURL to Fetch Converter, then select Convert to Fetch. Inspect the generated code and diagnostics before copying. SyntaxDock never executes the command, the generated JavaScript or the represented request. Conversion stays in your browser.
Start with a simple GET
curl https://example.test/users
Generated Fetch code:
const response = await fetch("https://example.test/users", {
method: "GET",
redirect: "manual",
});
The converter explicitly emits redirect: "manual" by default. Supported -L or --location requests emit "follow"; browser redirect behavior still has its own restrictions. The generated code uses top-level await, so run it later in a module or adapt it to an async function.
Map the method and headers
curl 'https://example.com/items?limit=5' \
-X POST \
-H 'Content-Type: application/json' \
--data-raw '{"name":"sample"}'
Generated Fetch code:
const response = await fetch("https://example.com/items?limit=5", {
method: "POST",
headers: [
["Content-Type", "application/json"],
],
redirect: "manual",
body: "{\"name\":\"sample\"}",
});
The URL becomes the Fetch URL argument. The method and supported headers become options. Body flags can imply POST when no explicit method is present, while -G moves supported data into the query string. Review diagnostics when combinations cannot be represented safely. The example contains no credentials and is never sent by the converter.
JSON and raw request bodies
A JSON-looking body is still request text; the content type tells the recipient how to interpret it. SyntaxDock preserves supported body content in generated JavaScript rather than running it. Shell quoting and JavaScript string escaping differ, so use the generated representation instead of pasting shell quotes directly into Fetch.
The supported --json option implies POST and supplies both JSON Content-Type and Accept headers unless overridden or suppressed. It does not validate the JSON body:
curl --json '{"name":"Ada"}' https://example.test/users
Generated Fetch code:
const response = await fetch("https://example.test/users", {
method: "POST",
headers: [
["Content-Type", "application/json"],
["Accept", "application/json"],
],
redirect: "manual",
body: "{\"name\":\"Ada\"}",
});
URL-encoded data and query parameters
Supported URL-encoded data is converted according to the option's encoding semantics. Existing query parameters remain part of the URL. Do not assume raw data and URL-encoded data are interchangeable: spaces, plus signs and percent escapes can change meaning. Review the generated URL and body, especially when combining repeated data options.
Repeated ordinary data pieces are joined with an ampersand and imply POST with a form content type:
curl -d a=1 -d b=2 https://example.test/submit
Generated Fetch code:
const response = await fetch("https://example.test/submit", {
method: "POST",
headers: [
["Content-Type", "application/x-www-form-urlencoded"],
],
redirect: "manual",
body: "a=1&b=2",
});
With -G, data moves into the query. Here the existing parameter and fragment are retained, and the space becomes %20:
curl -G -d a=1 --data-urlencode 'b=two words' 'https://example.test/search?old=yes#part'
Generated Fetch code:
const response = await fetch("https://example.test/search?old=yes&a=1&b=two%20words#part", {
method: "GET",
redirect: "manual",
});
Simply adding -X GET does not move a body into the URL. This combination is rejected because browser Fetch does not allow a GET body:
curl -X GET -d a=1 https://example.test/search
Multipart text fields
Supported text-only multipart fields become a FormData representation. Browser FormData supplies the multipart boundary; manually retaining a boundary from a captured request would be misleading. File uploads, file-backed data such as --data @payload.json, and shell substitutions cannot be resolved from static text and are rejected rather than read or executed.
This supported text-only example creates FormData without manually setting its Content-Type:
curl -F 'name=one=two' --form-string 'literal=@kept' https://example.test/form
Generated Fetch code:
const formData = new FormData();
formData.append("name", "one=two");
formData.append("literal", "@kept");
const response = await fetch("https://example.test/form", {
method: "POST",
redirect: "manual",
body: formData,
});
Shell quoting and file input
The tokenizer supports static single and double quotes, backslash escapes and line continuations, plus a limited set of ANSI-C quoted escapes. This is not a general shell interpreter or a promise of PowerShell or Windows CMD compatibility. Quote URLs containing query punctuation. Unmatched quotes are errors; active variables, command substitution and pipelines are rejected. Shell-looking characters inside single quotes can remain literal data.
This file-backed body is rejected; the converter does not read the file:
curl --data @payload.json https://example.test/submit
By contrast, --data-raw keeps the same at-sign text literal. It does not load a JSON file, and without an explicit content type it uses the ordinary form content type:
curl --data-raw @payload.json https://example.test/submit
Generated Fetch code:
const response = await fetch("https://example.test/submit", {
method: "POST",
headers: [
["Content-Type", "application/x-www-form-urlencoded"],
],
redirect: "manual",
body: "@payload.json",
});
Browser-controlled behavior and credentials
Browsers control some request headers, cookies, redirects and cross-origin behavior. A syntactically valid Fetch call may be blocked by CORS or differ from cURL's networking behavior. Conversion cannot bypass those browser rules. Review credential-related warnings and avoid treating captured Cookie headers as a portable browser authentication mechanism.
Review captured requests before sharing them: authorization headers and other supplied values can remain in generated code. Local conversion does not remove secrets for you. These examples contain no real credentials.
Which options need special attention?
| Options | Conversion behavior |
|---|---|
-X, -H, supported data options, text-only forms | Represented as method, headers and body, subject to browser compatibility checks. |
--silent, --show-error, --verbose, --include, --output, --remote-name, --progress-bar | Accepted and ignored. Conversion does not write output files or reproduce terminal output. |
--proxy, SOCKS options, --resolve, --connect-to, --interface, --unix-socket, certificate/key/CA options, --max-redirs | Produce warnings because browser Fetch cannot reproduce those transport settings. |
--insecure | Produces a warning; browser Fetch cannot disable certificate verification. |
--digest, --ntlm, --negotiate, --anyauth, unknown options | Rejected. Unsupported options stop conversion rather than being silently discarded. |
--next, multiple URLs, URL transfer expansion, file-backed bodies or headers | Rejected. Only a single supported static request is converted. |
Static conversion limits and the reverse workflow
SyntaxDock accepts a supported subset of cURL options, not a complete shell script. Pipelines, command substitution, environment expansion, file access and arbitrary execution are outside the conversion contract. Input is limited to 1 MiB and generated output to 2 MiB; oversized content is rejected without truncation.
For the reverse direction, use the Fetch to cURL Converter. For examples and limitations, read the Fetch to cURL guide. It statically parses supported Fetch expressions without evaluating JavaScript. Runtime values, arbitrary function calls and application state cannot be reconstructed. Review either conversion in your own application context before running a request elsewhere.