Curl to fetch is a straight swap: the URL becomes the first argument to fetch(), and the method, headers and body go into its options object. Paste the command into the free AyeTab cURL to Code page, leave the toggle on fetch, and you get JavaScript you can drop into a browser app or a Node script.

The same page also writes Python, which is handy when the backend and the frontend need the same call. This guide sticks to the JavaScript side.

What the conversion looks like

Take a typical command from an API reference:

curl -X PUT https://api.example.com/scores/42 \
  -H "Content-Type: application/json" \
  -d '{"points":1200}'

AyeTab turns it into this:

const response = await fetch("https://api.example.com/scores/42", {
  method: "PUT",
  headers: {
    "Content-Type": "application/json"
  },
  body: "{\"points\":1200}"
});
const data = await response.text();
console.log(data)

Each piece of the curl command has a home:

curl fetch
URL First argument
-X PUT method: "PUT" (GET when there is no -X)
-H "Name: value" headers object
-d, --data, --data-raw body

The converter joins commands split over several lines with backslashes, so you can paste a multi-line example as is. If a command sends a body but has no -X, add -X POST before converting so the method in the code matches what the request needs. Then copy the result, or download it as a file.

Four things to fix after converting

Check response.ok. A fetch() promise only rejects on network failures or a malformed URL. A 404 or a 500 still resolves, so test response.ok before trusting the data.

Parse JSON properly. The generated code reads the reply with response.text(). If the API returns JSON, switch to await response.json(), and build the body with JSON.stringify() from a real object so you can edit it without fighting escaped quotes.

Expect CORS in the browser. curl does not care which origin you call from. A page in a browser does, and a cross-origin API has to allow your site. If a call that worked in the terminal fails in the browser, CORS is the first thing to check. In Node the restriction does not apply.

Use top-level await with care. The snippet uses await at the top. That works in ES modules, in Node with .mjs files, and in the dev tools console. Inside older scripts, wrap it in an async function.

Node or browser

fetch() is built into modern browsers, and Node has it as a global too: the Node docs list it as stable since version 21 and available without a flag since 18. That means the same converted snippet runs in both places with no extra package, CORS aside.

Keep tokens off other people's servers

The curl commands worth converting are often the ones you copied from your own app with Copy as cURL in dev tools, and those carry cookies and bearer tokens. AyeTab parses the command in your browser tab and does not upload it, and it works offline once loaded, so a live session token never leaves your machine during the conversion.

When to use something else

For a language other than JavaScript or Python, or a command full of form fields and file uploads, curlconverter is the better tool: it is open source and supports many more targets, including several Node.js HTTP clients. For a quick fetch snippet, AyeTab is faster to reach. Install the AyeTab Chrome extension and the converter sits on every new tab, a Ctrl+K away, next to a JSON formatter and other everyday tools.