cURL to JS Fetch
Convert a curl command to JavaScript fetch
About cURL to JS Fetch
Turns a cURL command into an awaited JavaScript fetch call that runs in the browser or in Node.js 18+ without imports. JSON payloads are wrapped in JSON.stringify, -F fields become a FormData object, and -u user:pass becomes an Authorization: Basic header. Conversion happens in your browser, so tokens in the pasted command are never sent anywhere.
Category: API.
Frequently asked questions
Does the fetch snippet need Node.js or an npm package?
▾
No package is imported: fetch is built into modern browsers and into Node.js 18 and later. The snippet uses top-level await and ends with response.json(), so run it in an ES module, an async function or the DevTools console, and switch to response.text() if the API does not return JSON.
How are JSON, URL-encoded and -F bodies written for fetch?
▾
A -d payload that parses as JSON is wrapped in JSON.stringify(), one sent with Content-Type: application/x-www-form-urlencoded becomes new URLSearchParams(), and anything else stays a plain string. -F fields are appended to a FormData object, which fetch sends as multipart/form-data; a file reference like @photo.jpg is copied as text, not uploaded.
What happens to -u, -k and -L in the fetch output?
▾
-u user:pass becomes an Authorization: Basic header whose Base64 value is computed during conversion. -k is dropped because the fetch API has no option to skip certificate checks, and -L is not needed since fetch follows redirects by default.
Why can the fetch code fail in a browser when the cURL command works?
▾
Browsers enforce CORS, so the API must allow your page's origin, and they silently drop headers that scripts may not set, such as Cookie. Cookies passed with -b are not converted either: add them as a Cookie header when running in Node.js, or use credentials: 'include' to send the browser's own cookies.