cURL to Fetch
Paste any curl command and get ready-to-run JavaScript fetch code — async/await, promise chain, or bare.
About cURL to Fetch Converter
This tool converts any curl command into an
equivalent JavaScript fetch() call. Pick
from three output styles: async/await with full try/catch error handling (recommended for
modern JavaScript and TypeScript), promise chains using .then().catch() (useful in older codebases or when you want to avoid async propagation), or a bare fetch call (quick and minimal).
Everything runs 100% in your browser — your commands, tokens, and API keys never leave your device.
Parsing handles multi-line commands with backslash continuation, single and double quotes, headers,
JSON bodies, form fields, basic auth (converted to btoa()),
cookies, user-agent, referer, and more.
How to Use
- Paste your curl command on the left (multi-line with
\continuations is fine), or click Load Sample to try it out. - Pick your code style: async/await, promise chain, or bare fetch.
- Choose how to parse the response:
.json(),.text(), or return the raw Response object. - View the fetch code on the right — it updates as you type or change options.
- Copy the result and paste it into your JavaScript or TypeScript file. Replace placeholder tokens/cookies before shipping.
Supported curl Flags
Request
-X / --request— HTTP method-H / --header— request headers-d / --data / --data-raw— body-F / --form— FormData-G / --get— force GET-I / --head— HEAD request
Options
-u / --user— basic auth (→btoa())-A / --user-agent-e / --referer-b / --cookie(→credentials: 'include')-L / --location-k / --insecure--compressed
Common Use Cases
- API integration: Drop in a curl example from API docs (Stripe, OpenAI,
GitHub, Twilio) and get working
fetchcode instantly. - Frontend apps: Paste server-side curl snippets and convert them into
browser-compatible
fetchcalls for React, Vue, Svelte, and vanilla JS projects. - Node.js scripts: Fetch is built into Node 18+ — convert curl commands directly into server-side JavaScript without extra dependencies.
- Browser DevTools: Right-click a network request → "Copy as cURL", paste here, and get code you can drop into the console or a test script.
- Learning fetch: Compare async/await, promise chain, and bare styles side by side to pick the one that fits your codebase.
Frequently Asked Questions
Does the output work in the browser and Node.js?
Yes. fetch has been built into every modern
browser for years and into Node.js since version 18. No polyfill or import is needed. The
only browser-specific call is btoa() used for
basic auth — Node.js 16+ supports it too, or you can swap it for Buffer.from(...).toString('base64').
Which code style should I choose?
Use async/await for most modern projects — it reads top-to-bottom and makes error handling with try/catch straightforward. Use promise chains if you're working in a codebase that avoids async functions or needs to integrate with promise-based utilities. Use bare fetch when you just want the minimal call and will handle the response elsewhere.
Does this tool handle multi-line curl commands?
Yes. Backslash + newline continuations (\ at
the end of a line) are joined before parsing, so you can paste curl commands exactly as
they appear in documentation.
How is form data (-F) converted?
-F key=value pairs become a new FormData() object with formData.append() calls. For file uploads
(-F file=@path), replace the string value
with a File or Blob instance (e.g. from an <input type="file">).
How is basic auth (-u user:pass) handled?
The credentials are wrapped in btoa('user:pass') and sent as an Authorization: Basic <base64> header.
Note: sending credentials from a browser exposes them to anyone with access to the page
source — prefer server-side requests for sensitive APIs.
What about cookies and CORS?
If your curl command uses -b, the converter
adds credentials: 'include' so the browser
sends cookies. The target server must respond with Access-Control-Allow-Credentials: true and a
specific (non-wildcard) Access-Control-Allow-Origin for the request to succeed.
Is my curl command sent to a server?
No. Parsing and code generation run entirely in your browser using JavaScript. Your curl commands — including any API tokens, bearer tokens, or cookies — never leave your device, so it's safe to use with production credentials.
Why doesn't fetch reject on HTTP errors like 404 or 500?
By design. fetch only rejects on network failures
(DNS, offline, CORS). HTTP error statuses still resolve the promise — the generated code
explicitly checks response.ok and throws so your
try/catch or .catch() handles both cases uniformly.
Can I use the -k / --insecure flag?
Browsers don't let JavaScript bypass TLS verification, so -k has no direct equivalent in fetch on the web. In Node.js you can set NODE_TLS_REJECT_UNAUTHORIZED=0 as an env var,
but only for local development — never in production.