Conversion guides
How to convert cURL to JavaScript fetch
cURL commands convert naturally to JavaScript fetch: the URL, method, headers, and body become a fetch call and options object.
Basic fetch conversion
A simple curl GET request becomes fetch(url). You can await the response and then read JSON, text, blobs, or streams depending on the API.
const response = await fetch('https://api.github.com/repos/curl/curl');
const data = await response.json();
console.log(data);POST JSON with fetch
For JSON requests, fetch uses an options object. Set method, headers, and body. Remember that fetch expects the body to be a string, so use JSON.stringify for JSON payloads.
const response = await fetch('https://api.example.com/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'Ada' }),
});fetch does not throw on HTTP errors
A common difference between curl and fetch is error behavior. fetch only rejects on network errors, not on HTTP 404 or 500 responses. Check response.ok or response.status yourself.
Where fetch works
fetch works in modern browsers, Node.js 18+, Deno, Bun, Cloudflare Workers, and many edge runtimes. For older Node.js versions, use node-fetch, Axios, Got, or another HTTP client.
Try it with curlcode
Have a curl command already? Paste it into one of the converters below to generate language-specific HTTP request code.
Frequently asked questions
Does fetch work in Node.js?
Yes in Node.js 18 and newer. Older versions need a package such as node-fetch.
How do curl headers map to fetch?
They become properties in the headers object.
Why does fetch not throw on 404?
The request completed successfully at the network level. You need to check response.ok for HTTP status errors.
Can I convert cURL to Axios instead?
Yes. Axios is often preferred in Node.js and some frontend projects.
Related guides
What does cURL mean?
Learn what cURL means, why developers use it, and how a simple curl command turns a URL into a repeatable API request.
What is a cURL command?
A practical explanation of curl commands, their structure, common flags, and how developers use them to test APIs.
How to copy as cURL from Chrome DevTools
Use Chrome DevTools to copy a real browser request as cURL, inspect headers and cookies, and convert it into reusable code.