Skip to content

Menu

Curl to Fetch

Convert curl commands to fetch()

Runs entirely in your browserAPI & HTTPFree, no sign-up
Loading tool

01What is Curl to Fetch?

Copy as cURL is the fastest way to capture a request, but you usually want it as JavaScript. This tool takes a curl command and gives you equivalent fetch code. You paste the command, choose async/await or .then() style, and press Convert. The command is read the way a shell reads it, including quotes, backslash line continuations and $'...' strings. Options are then read the way curl reads them. A value-taking option like --retry 3 or --referer https://google.com is never mistaken for the request URL. -X sets the method and -H adds headers. -d, --data-raw, --data-binary and --data-urlencode build the body, with repeated pieces joined by & as curl does. Sending data switches GET to POST and adds the form-urlencoded Content-Type curl would send. -G moves the data into the query string, --json sends JSON, and -F fields become a FormData body. -u becomes a Basic Authorization header built with btoa(), since fetch has no username option. -b cookie strings become a Cookie header, and -A and --oauth2-bearer become headers too. Timeouts use the AbortSignal.timeout() method from the WHATWG DOM standard. -m or --max-time adds signal: AbortSignal.timeout(ms), so the request aborts like curl's total time limit. --connect-timeout has no fetch equivalent and gets a comment instead. If the Content-Type is JSON and the body parses, it's re-emitted as a pretty-printed JSON.stringify() call, which is much easier to edit than an escaped string. The generated code checks response.ok, throws on HTTP errors and parses the body as JSON. In .then() style it also logs the data and catches errors. Here's a small example. curl -F name=Alice -F [email protected] https://api.example.com/upload produces a FormData object with form.append("name", "Alice"). The file field becomes form.append("avatar", fileInput.files[0]) with a comment naming me.png, and the method is POST. Options it doesn't recognise are listed in a note at the top, so nothing disappears quietly. Some limits to keep in mind. A browser page can't read local files, so @file references turn into placeholders. Browsers also refuse to let fetch set a Cookie header, so that part only works in Node or similar runtimes. Retries, proxies and TLS flags like -k have no fetch equivalent. And the output always calls response.json(), so swap it for text() on endpoints that don't return JSON. The conversion runs in your browser and nothing is sent to a server.

Front-end and Node.js developers use it to turn a curl command from docs or DevTools into fetch code they can drop into an app or test. The tool runs entirely in your browser, so your data never leaves your device.

02How to use Curl to Fetch

  1. Paste the command into cURL Command, line breaks and all.
  2. Pick a Style: async/await or .then().
  3. Click Convert.
  4. Read the JavaScript Fetch Code panel and click Copy.
  5. Use Reset to clear both input and output.

03Worked examples

Input: curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d '{"name":"Alice"}'
Result: async function makeRequest() { const response = await fetch("https://api.example.com/users", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ "name": "Alice" }), }); …
A JSON body is turned into a JSON.stringify() call so it stays easy to edit.
Input: curl -u admin:secret https://api.example.com/me
Result: … headers: { "Authorization": "Basic " + btoa("admin:secret"), }, …
fetch has no -u option, so basic auth becomes an Authorization header.
Input: curl -d "name=Alice" -d "role=admin" https://api.example.com/users
Result: … method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", }, body: "name=Alice&role=admin", …
As in curl, -d without -X implies POST, and repeated -d values are joined with &.
Input: curl --max-time 10 https://api.example.com/health
Result: … const response = await fetch("https://api.example.com/health", { signal: AbortSignal.timeout(10000), }); … // On timeout, fetch rejects with a DOMException named "TimeoutError".
--max-time is in seconds; AbortSignal.timeout takes milliseconds.
Input: curl https://api.example.com/users (Promise style)
Result: fetch("https://api.example.com/users") .then((response) => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); }) …
A plain GET needs no options object at all.
Input: curl -F name=Alice -F [email protected] https://api.example.com/upload
Result: … const form = new FormData(); form.append("name", "Alice"); form.append("avatar", fileInput.files[0]); // file: me.png const response = await fetch("https://api.example.com/upload", { method: "POST", body: form, }); …
-F builds a FormData body. The @file becomes a placeholder you point at a real file input (excerpt).

04Common use cases

  • Turning a 'Copy as cURL' request from Chrome DevTools into code for a React app
  • Converting API documentation examples from Stripe or GitHub docs into JavaScript
  • Porting a shell script's curl calls to a Node.js 18+ service that has native fetch
  • Reproducing a failing request from a bug report inside a quick test file
  • Showing newer developers how curl flags map to fetch options

05Tips

  • After switching style, press Convert again. The output doesn't refresh on its own.
  • Browsers block setting the Cookie header from fetch, so cookie handling only works as written in Node or similar runtimes. In browsers use credentials: 'include'.
  • Move any tokens or passwords from the converted code into environment variables before committing it.
  • The generated code always calls response.json(). Change it to text() or blob() for non-JSON endpoints.
  • For -F file uploads, replace fileInput.files[0] with your own File or Blob, and don't set Content-Type yourself. fetch adds the multipart boundary.

06Related concepts

Fetch API, curl, HTTP headers, basic authentication, async/await.

Frequently Asked Questions

What is Curl to Fetch?

Curl to Fetch is a free, browser-based developer tool on AIDToolStack. Convert curl commands to fetch() It requires no installation or sign-up and works entirely in your browser.

Is Curl to Fetch free to use?

Yes. No sign-up, no fees and no usage cap.

Does Curl to Fetch store my data?

No. It runs in your browser; nothing is uploaded.

Cheat sheet

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe