Trexmi
Converter Ready

cURL to Fetch

Convert one cURL HTTP request into reviewable JavaScript Fetch code with method, headers, inline body, redirect policy, timeout, and status handling.

Parse one HTTP or HTTPS cURL request Preserve explicit method and headers Convert inline request data Map -G data to URL query parameters
No request is sent. The converter supports one HTTP(S) URL plus common method, header, inline body, auth, cookie, redirect, HEAD, GET-query, and timeout options. Files, multipart forms, proxies, certificates, and unsupported flags are rejected.
INPUT cURL command *
0 chars0 words0 lines
Ctrl / ⌘ + Enter
Generated code
About the tool

What cURL to Fetch does

cURL to Fetch Converter translates one HTTP or HTTPS cURL command into JavaScript built around fetch(). The generated request keeps the parsed method, URL, headers, inline body, redirect choice, and maximum time visible for review.

The converter parses text only; it does not execute the cURL command or contact its destination. It accepts common request options and rejects file-backed bodies, multipart forms, proxy settings, certificates, multiple URLs, and unknown flags instead of silently pretending those behaviors were preserved.

cURL and Fetch do not have identical runtime models. Browser Fetch is governed by same-origin and CORS rules, filters some headers, and does not expose every redirect response. Treat the result as a clear starting point, then test it in the intended browser, worker, or server-side JavaScript runtime.

cURL to Fetch converter mapping a cURL request to JavaScript Fetch code
Inspect the URL, method, headers, body, redirect mode, timeout, and response handling before running the generated code.

How to use

  1. Paste one command. Start with curl and include one complete http:// or https:// URL.
  2. Keep data explicit. Inline -d, --data-raw, --data-binary, or --json values. The converter never opens @file references.
  3. Convert. Common headers, Basic or Bearer authorization, cookies, user agent, referer, -L, -G, -I, and --max-time are mapped.
  4. Review browser differences. Check forbidden headers, credentials, CORS, redirects, and whether the payload should be JSON, form data, or raw text.
  5. Test safely. Replace sample credentials and call a non-production endpoint before integrating the code.
Built for the task

Why use cURL to Fetch?

Focused controls, predictable output, and a workflow designed around this exact transformation.

01

Readable Fetch request

Generate one explicit options object instead of manually translating shell quoting.

02

Unsupported input rejected

Avoid false conversions for files, multipart forms, proxies, certificates, and unknown flags.

03

Bounded execution

Carry a cURL maximum time into an AbortSignal timeout, with a 30-second default.

04

Visible response checks

Generate an HTTP status guard before reading and logging the response text.

Useful answers

Questions about cURL to Fetch

Practical details about input, output, privacy, limits, and the best way to use this tool.

01 Does cURL to Fetch send the request?

No. It parses the command and generates JavaScript text. The destination is contacted only if you later run that code.

02 Why is redirect set to manual without -L?

cURL does not follow HTTP redirects unless requested. Fetch normally follows them, so explicit manual mode makes the generated intent closer to the source command.

03 Can Fetch set Cookie or User-Agent headers?

Not reliably in a browser. The browser controls forbidden or restricted request headers. Server-side JavaScript runtimes can differ, so review those headers for the actual runtime.

04 Will a cross-origin request work?

Only when browser security rules allow it. Valid generated syntax does not bypass same-origin policy, a failed CORS preflight, mixed-content blocking, or certificate errors.

05 How does --json convert?

The inline JSON becomes a string body and the converter adds JSON Content-Type and Accept headers. Validate that the payload is appropriate for the receiving API.

06 What happens with curl -G?

Inline data chunks are joined as a query string and appended to the URL. Existing query parameters are retained, but advanced data-urlencode behavior is intentionally unsupported.

07 Why are GET and HEAD bodies rejected?

The Fetch request model does not allow a body with GET or HEAD. Use -G for query data or choose a body-capable method.

08 Which cURL features require manual conversion?

Multipart forms, uploads, local files, cookie jars, proxies, client certificates, shell variables, command substitution, multiple transfers, and unknown flags require a task-specific implementation.

Learn HTTP & Network Debugging

Read the HTTP Headers Guide

Connect DNS, redirects, HTTP headers, requests, responses, caching, security, and practical web diagnostics.

  • Requests and response headers
  • Redirect and cache diagnostics
  • Security and API debugging
Read guide Practical explanations and examples

Examples

Convert a JSON POST

Inline data implies POST when no request method is supplied. The body remains a string so its transmitted bytes stay reviewable.

Input
curl https://api.example.com/v1/users -H 'Content-Type: application/json' --data-raw '{"name":"Ada","active":true}'
Output
fetch("https://api.example.com/v1/users", { method: "POST", headers: {"Content-Type":"application/json"}, body: "{...}", redirect: "manual", signal: AbortSignal.timeout(30000) })

Convert query data with -G

The data chunks become a URL query instead of an invalid Fetch GET body.

Input
curl -G 'https://api.example.com/search' -d 'q=blueshoes' -d 'page=2'
Output
fetch("https://api.example.com/search?q=blueshoes&page=2", { method: "GET", ... })

Preserve redirect and timeout intent

Without -L the generator uses manual redirect mode to reflect cURL default behavior.

Input
curl -L --max-time 12 'https://example.com/latest'
Output
redirect: "follow" · signal: AbortSignal.timeout(12000)

Reject a file-backed upload

A text converter cannot safely reproduce unknown local file content.

Input
curl https://api.example.com/import --data-binary @payload.json
Output
Error: file-backed request bodies are not read; paste the body value directly.

How cURL options map to Fetch

-X or --request becomes the Fetch method. -H values become the headers object. Inline data becomes a string body and implies POST unless a method was explicit. -G moves that data to the URL query. -I becomes HEAD, -L selects follow redirects, and --max-time becomes an AbortSignal.timeout() value.

Use URL Parser to inspect the endpoint structure and Query String Parser to review parameters before conversion.

Browser headers, credentials, and CORS

cURL is a command-line client, while browser Fetch participates in the browser security model. A browser can block cross-origin requests, require a successful preflight, remove restricted headers, or manage cookies through the Fetch credentials mode instead of a manually supplied Cookie header. Generated code cannot change the remote server CORS policy.

If a request depends on cookies, browser authentication state, a client certificate, or a proxy, implement that behavior for the actual runtime instead of assuming a direct cURL equivalent.

Redirects, HTTP errors, and response bodies

The generated status guard throws when response.ok is false. Fetch itself normally resolves its promise even for HTTP 404 or 500, so checking the response is separate from catching network errors. The code reads response text because the converter cannot know whether the server returns JSON, HTML, an empty body, or binary data.

After running the request, inspect live response headers with HTTP Header Checker. For a backend-oriented alternative, convert the same source with cURL to Python Requests.

Limitations and safe review

The parser handles one HTTP(S) transfer, ordinary shell quotes and line continuations, common headers, inline bodies, Basic or Bearer auth, cookies, referer, user agent, redirects, GET-query mode, HEAD, and a bounded timeout. It deliberately rejects local files, multipart forms, uploads, proxies, certificates, insecure TLS flags, multiple URLs, and unsupported options.

Redact credentials before sharing generated code. Compare cURL behavior in the official cURL manual and browser request behavior in the WHATWG Fetch Standard.