$ Convert cURL to JavaScript fetch
Paste a cURL command and get async/await fetch() code for the browser or Node.js 18+, or switch to axios.
cURL Input
Paste a cURL command and select the output language.
Generated code
Ready to copy.
const response = await fetch("https://api.example.com/users", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer my-token-123"
},
body: "{\"name\":\"Alice\",\"email\":\"alice@example.com\"}"
});
const data = await response.json();
console.log(data);Why use an online cURL to fetch converter
API docs, Postman and the browser DevTools all hand you requests as cURL commands, but your frontend or Node.js code needs fetch(). Translating headers, auth and JSON bodies by hand is where subtle bugs creep in.
This cURL to fetch converter parses the command and outputs async/await fetch() code: -X becomes method, each -H becomes a headers entry, -d becomes body, and --user / --oauth2-bearer become an Authorization header. Switch to axios with one click.
Parsing happens entirely in your browser, so bearer tokens and cookies inside the command never leave your machine.
cURL to fetch converter use cases
cURL to fetch converter examples: input and output
POST JSON
Basic auth with --user
Common cURL to fetch converter errors and how to fix them
cause:cURL ignores CORS, browsers do not. The API does not return Access-Control-Allow-Origin for your origin.
fix:Call the API from your backend or a Node.js script, or enable CORS for your origin on the server.
cause:Browsers forbid setting the Cookie header from fetch.
fix:Use credentials: "include" so the browser sends its own cookies, or run the code in Node.js.
cause:The endpoint returned HTML or plain text (often an error page), not JSON.
fix:Check response.ok and response.headers.get("content-type") before calling response.json(), or use response.text().
How developers use the cURL to fetch converter in practice
The converter keeps the body exactly as in the cURL command. When you replace it with dynamic data, write body: JSON.stringify(payload) and keep the Content-Type header.
Unlike axios, fetch only rejects on network errors. Add if (!response.ok) throw new Error(response.status) after the call.
In Chrome DevTools, Network → right-click → Copy → Copy as fetch gives fetch code directly. Use the converter for cURL from docs, Postman or teammates.
When not to use the cURL to fetch converter
cURL to fetch converter limits and implementation notes
-X, -H, -d/--data, --user, --oauth2-bearer, --cookie, --insecure, -L and --max-time. Uncommon flags are ignored.
Multipart uploads (-F) are not converted into FormData.
Related guides
Standards & references
Related developer tools
Frequently asked questions about the cURL to fetch converter
How do I convert a cURL command to fetch?
Paste the command into the input. -X becomes the method option, each -H becomes an entry in headers, -d / --data becomes body, and --user or --oauth2-bearer become an Authorization header. The result uses async/await.
Does the generated fetch code work in Node.js?
Yes. fetch is built into Node.js 18 and later, so the same code runs in the browser and in Node without installing a package. On older Node versions use the axios output instead.
Why does my fetch request fail with CORS when cURL works?
cURL is not a browser, so it ignores CORS. In the browser the target server must return Access-Control-Allow-Origin for your origin. If it does not, call the API from your backend or from Node.js, where CORS does not apply.
Why are cookies or -k (--insecure) not carried over?
Browsers do not let fetch set the Cookie header manually (use credentials: "include" instead) and do not allow disabling TLS verification. The converter adds a note when a cURL flag has no fetch equivalent.
Can I get axios code instead of fetch?
Yes. Switch the target to JavaScript — axios. The same request is converted to an axios call with method, headers and data.
Is my cURL command sent to a server?
No. Parsing and code generation run entirely in your browser, so tokens and cookies in the command never leave your machine.
How do I handle the fetch response and parse JSON in JavaScript?
Modern fetch() code uses async/await: `const response = await fetch(url, options); const data = await response.json();`. Always verify `response.ok` to handle HTTP error status codes gracefully.