Quick answer
To convert cURL to fetch, map each flag to a fetch() option: -X becomes method, every -H becomes an entry in headers, and -d becomes body (URLSearchParams for form data, JSON.stringify for JSON). Paste a cURL command into Playxoft's free cURL to Fetch converter and it writes async/await or .then() code for you, handling shell quoting, multipart forms, basic auth and timeouts entirely in your browser.
- Bash, cmd and PowerShell input
- Request inspector
- JSON, forms and file uploads
- async/await or .then()
- Credential warnings
- Runs in your browser
How to use the cURL to Fetch Converter
- 1Paste a command into cURL command, or open Load example. Bash, Windows cmd and PowerShell syntax are detected automatically.
- 2Check Parsed request to confirm the method, URL, headers and body are what you expect.
- 3Pick async/await or .then(), and keep Check response.ok on so 4xx and 5xx responses throw.
- 4Read the notes under the editor: they flag anything fetch() can't reproduce, such as -k or a proxy in the browser.
- 5Click Copy (or press Ctrl+Enter in the editor) or download request.js, then run it in Node.js 18+, Deno, Bun or the browser.
cURL flags cheat sheet: what does each option become in fetch()?
Most of a cURL command maps one-to-one onto the options object fetch() takes as its second argument:
| cURL | fetch() equivalent |
|---|---|
-X POST | method: "POST" |
-H "Name: value" | headers: { Name: "value" } |
-d "a=1&b=2" | body: new URLSearchParams({ a: "1", b: "2" }) (sent as form data, like curl; a raw string body would go out as text/plain) |
--json '{…}' | body: JSON.stringify({…}) plus JSON Content-Type and Accept headers |
-F name=@file | const form = new FormData(), then body: form |
-u user:pass | Authorization: "Basic " + btoa("user:pass") |
-b "a=1" | A Cookie header (Node.js, Deno and Bun only) |
-G -d q=x | The data moves into the URL's query string |
-m 10 | signal: AbortSignal.timeout(10000) |
-L | Nothing: fetch() follows redirects by default |
-I | method: "HEAD" |
-k, -x | No browser equivalent; in Node.js, an undici Agent or ProxyAgent as dispatcher |
One difference is easy to miss: fetch() only rejects on network failures. A 404 or 500 response still resolves, so the generated code checks response.ok and throws, which is closer to what curl -f does.
Fetch vs Axios: which should you use?
Both send the same HTTP request; they differ in how much they do for you.
| fetch() | Axios | |
|---|---|---|
| Install | Built into browsers, Node.js 18+, Deno and Bun | npm install axios |
| JSON request body | You call JSON.stringify and set Content-Type | Pass an object; Axios serializes it |
| HTTP errors (4xx, 5xx) | Resolve normally; check response.ok | Reject with an error |
| Timeouts | AbortSignal.timeout(ms) | The timeout option |
| Query parameters | Build them with URLSearchParams | A params object |
| Upload progress | No progress events | onUploadProgress in browsers and Node.js (Axios 1.x) |
| Interceptors | Wrap fetch() yourself | Built in |
Choose fetch() when you want zero dependencies, edge and serverless runtimes, or streamed responses. Choose Axios when your team already uses it, or when interceptors (token refresh, logging) and upload progress matter. The cURL to Axios converter writes the Axios version of the same command.
Why does my converted fetch() call fail in the browser?
Code that runs fine in Node.js can fail inside a web page for three browser-only reasons:
- CORS. curl ignores it; browsers enforce it. If the API doesn't send
Access-Control-Allow-Originfor your site, the response is blocked however correct the code is. Call the API from your server instead, or ask its owner to allow your origin. - Forbidden headers. Browsers silently drop headers they manage themselves, including
Cookie,Host,Origin,Referer,Content-Length,Accept-Encodingand anything starting withSec-. To send cookies, usecredentials: "include"and let the browser attach them. - TLS and proxies. A page can't skip certificate checks or choose a proxy, so the
-kand-xtranslations only work in Node.js.
Turn on Drop browser headers to strip the sec-ch-ua and sec-fetch-* noise that "Copy as cURL" includes. The converter also removes Content-Length and Accept-Encoding on its own, because fetch() computes or negotiates them.
How do I copy as cURL in Chrome or Firefox DevTools?
- Open DevTools with F12 (Cmd+Option+I on a Mac) and select the Network panel.
- Reload the page or trigger the action, then filter by Fetch/XHR to hide images and scripts.
- In Chrome or Edge, right-click the request and choose Copy, then Copy as cURL. Windows offers two versions, (bash) and (cmd); both work here.
- In Firefox, right-click the request and choose Copy Value, then Copy as cURL. In Safari, right-click it in the Web Inspector's Network tab and choose Copy as cURL.
- Paste it into the converter on this page.
Chrome can also Copy as fetch, but that output carries browser-only settings such as mode, credentials and referrerPolicy, and no error handling. Converting the cURL version gives you code that also runs in Node.js.
Is it safe to paste a cURL command that contains tokens?
Here, yes: the converter runs entirely in your browser, makes no network requests and doesn't save what you paste. Reloading the page clears it.
The command itself is the risk. "Copy as cURL" includes your live session cookies and Authorization header, which work like your password until they expire. Before the generated code goes into a ticket, a chat or a repository:
- Check the Contains credentials badge; lines holding secrets are marked in amber.
- Move secrets to environment variables. Write the token as
$API_TOKENin the command and the converter emitsprocess.env.API_TOKEN. - If a token has already leaked, revoke it. Deleting the message is not enough.
Frequently asked questions
Last updated by the Playxoft engineering team.