cURL to Fetch Converter Online

Convert a curl command to a JavaScript fetch() call instantly in your browser. Your request stays on your device.

Your curl command is converted locally in your browser and never uploaded, but avoid pasting real production tokens or credentials into any tool.

Built and maintained by Udit Agarwal

Inspecting an API URL? Try the URL Parser.

About cURL to Fetch

This curl to fetch converter takes a curl command you copied from your terminal, browser DevTools, or API docs and rewrites it as a ready-to-run JavaScript fetch() call. As a curl to fetch converter it parses common flags like -X, -H, -d, --data-raw, --json, -u, -b, and -G, infers the right HTTP method, sets sensible Content-Type headers, and pretty-prints JSON bodies with JSON.stringify. Use it to move a curl request into front-end code, a Node script, or a quick test without hand-translating syntax. It is built for developers, QA engineers, and anyone wiring up API calls who wants a fast curl to javascript translation. The conversion runs entirely in your browser, so the command you paste is processed locally and never leaves your device.

Features

  • Parses methods (-X/--request) and infers GET or POST automatically when none is given
  • Converts -H/--header flags into a structured fetch headers object
  • Handles -d, --data-raw, --data-ascii, --data-binary, and --json request bodies
  • Pretty-prints valid JSON bodies with JSON.stringify and adds the matching Content-Type
  • Encodes -u/--user basic auth into an Authorization header and maps cookies, user-agent, and referer
  • Rewrites -G/--get requests by appending data as a query string
  • Warns about flags with no fetch equivalent, like -k, -L, and output-to-file options
  • Copy the result or download it as request.js with one click

How to use the cURL to Fetch

  1. Paste your curl command into the cURL command box.
  2. Read the generated fetch() equivalent in the output panel on the right.
  3. Check the warning banner for any flags that were ignored or adjusted.
  4. Click Copy to grab the fetch code, or download it as request.js.

Example

Input

curl https://api.example.com/users \
  -H "Authorization: Bearer TOKEN" \
  -d '{"name":"Ada"}'

Output

const response = await fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Authorization": "Bearer TOKEN",
    "Content-Type": "application/x-www-form-urlencoded"
  },
  body: "{\"name\":\"Ada\"}",
});

const data = await response.text();

A -d body defaults to POST with a form-urlencoded Content-Type.

Common errors & troubleshooting

  • The output shows "Command should start with curl" or "No URL found in the curl command". — Make sure the pasted text begins with curl and includes a full URL; the converter expects a real curl invocation.
  • A JSON body comes out as a form-urlencoded string instead of JSON.stringify. — Send it with --json or add -H "Content-Type: application/json" so the converter knows to wrap valid JSON in JSON.stringify.
  • Flags like -k/--insecure or -L/--location seem to disappear. — These have no fetch equivalent; browsers always enforce TLS and follow redirects by default, so the converter notes them as warnings and drops them.
  • --data-urlencode values are not re-encoded. — The converter keeps these verbatim and warns you; encode the value yourself if the endpoint needs strict URL encoding.

Frequently asked questions

What is the cURL to Fetch converter?
It is an in-browser tool that parses common curl flags including -X, -H, -d and its variants, --json, -u, -b, -A, -e, -G, and --url, then builds an equivalent JavaScript fetch() call with the right method, headers, and body.
How do I convert a curl command to fetch?
Paste your curl command into the input box and the cURL to Fetch converter instantly renders the fetch() equivalent on the right, which you can copy or download as request.js.
How does the cURL to Fetch converter decide the HTTP method?
If you pass -X or --request it uses that; otherwise it defaults to POST when a data body is present and GET when there is none.
Does it handle basic auth from -u and -G query data?
Yes. A -u or --user value is base64-encoded into an Authorization: Basic header, and with -G your -d data is appended to the URL as a query string while the request body stays empty, just like curl.
Is my curl command sent anywhere when I convert it?
No. The curl to fetch conversion runs entirely in your browser, so the command and any tokens in it are processed locally and never leave your device.

Related tools

Guides

More API Tools tools

  • URL Parser — Break a URL into its parts and list query parameters.
  • API Request Client — Send HTTP requests, build headers and params, inspect responses — your last 25 requests are saved locally.
  • URL Builder & UTM Generator — Construct and validate fully encoded production URLs with standard analytics query flags (UTM) or custom query arrays.
  • OpenAI API Tester — Build, run and copy OpenAI Chat Completions API requests as cURL, Python and JavaScript.
  • Anthropic Claude API Tester — Build, run and copy Anthropic Claude Messages API requests as cURL, Python and JavaScript.
  • Google Gemini API Tester — Build, run and copy Google Gemini generateContent API requests as cURL, Python and JavaScript.
  • Replicate API Tester — Build, run and copy Replicate prediction API requests as cURL, Python and JavaScript.
  • Hugging Face API Tester — Build, run and copy Hugging Face Inference API requests as cURL, Python and JavaScript.
  • cURL to Python — Convert a curl command to Python requests code.
  • cURL to Go — Convert a curl command to Go net/http code.
  • cURL to PHP — Convert a curl command to PHP cURL code.
  • cURL to Node.js (axios) — Convert a curl command to Node.js axios code.

See all API Tools tools (24) · All tools