Code converters

cURL to Fetch Converter

Paste a cURL command from Chrome DevTools or API docs and get clean, runnable fetch() code, with the request decoded so you can check every header.

  • Free foreverNo trial, no paywall, no usage limits.
  • No sign-upOpen the page and start. We never ask for an email to use a tool.
  • PrivateEverything runs in your browser. Your input is never uploaded or stored on our servers.
  • Works offlineOnce the page has loaded, the tool keeps working without a connection.
InputAuto-detects Bash (Copy as cURL (bash), API docs), Windows cmd (Copy as cURL (cmd), with ^ escapes) and PowerShell (backtick line breaks). Pick one if the guess is wrong.
Top-level await: reads top to bottom. Works in ES modules, Deno, Bun and the browser console.A promise chain with .then() and .catch(), for code that can't use await.
fetch() only rejects on network failures; a 404 or 500 still resolves. This adds a response.ok check that throws.
curl follows redirects only with -L. On: without -L the code stops at a 3xx response, exactly like curl. Off: keep the library's default.
Leaves out headers a browser adds by itself (sec-ch-ua, sec-fetch-*, priority…). They are noise when you replay a DevTools request from code.

cURL command

Paste a command from DevTools (Copy as cURL), API docs or your terminal. You can also drop a .sh or .txt file here.
Clear

JavaScript · fetch()

Runnable JavaScript that sends the same request. Lines marked in amber contain credentials.
Wrap long linesCopyDownload request.js
Your JavaScript code appears here as you type.
Nothing leaves your browser.
Paste a command or load an example. It converts as you type, and nothing leaves your browser.

Parsed request

What curl would send, decoded: method, URL, query, headers, cookies and body.

Paste a command to see its method, URL, query parameters, headers, cookies and body, decoded.

Need this built into your own API or pipeline? Talk to our team

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

  1. 1Paste a command into cURL command, or open Load example. Bash, Windows cmd and PowerShell syntax are detected automatically.
  2. 2Check Parsed request to confirm the method, URL, headers and body are what you expect.
  3. 3Pick async/await or .then(), and keep Check response.ok on so 4xx and 5xx responses throw.
  4. 4Read the notes under the editor: they flag anything fetch() can't reproduce, such as -k or a proxy in the browser.
  5. 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:

cURLfetch() equivalent
-X POSTmethod: "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=@fileconst form = new FormData(), then body: form
-u user:passAuthorization: "Basic " + btoa("user:pass")
-b "a=1"A Cookie header (Node.js, Deno and Bun only)
-G -d q=xThe data moves into the URL's query string
-m 10signal: AbortSignal.timeout(10000)
-LNothing: fetch() follows redirects by default
-Imethod: "HEAD"
-k, -xNo 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
InstallBuilt into browsers, Node.js 18+, Deno and Bunnpm install axios
JSON request bodyYou call JSON.stringify and set Content-TypePass an object; Axios serializes it
HTTP errors (4xx, 5xx)Resolve normally; check response.okReject with an error
TimeoutsAbortSignal.timeout(ms)The timeout option
Query parametersBuild them with URLSearchParamsA params object
Upload progressNo progress eventsonUploadProgress in browsers and Node.js (Axios 1.x)
InterceptorsWrap fetch() yourselfBuilt 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-Origin for 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-Encoding and anything starting with Sec-. To send cookies, use credentials: "include" and let the browser attach them.
  • TLS and proxies. A page can't skip certificate checks or choose a proxy, so the -k and -x translations 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?

  1. Open DevTools with F12 (Cmd+Option+I on a Mac) and select the Network panel.
  2. Reload the page or trigger the action, then filter by Fetch/XHR to hide images and scripts.
  3. 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.
  4. 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.
  5. 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_TOKEN in the command and the converter emits process.env.API_TOKEN.
  • If a token has already leaked, revoke it. Deleting the message is not enough.

Frequently asked questions

Yes. fetch() follows up to 20 redirects by default, so curl -L needs no extra option. curl without -L stops at the 3xx response; turn on Match curl redirects to add redirect: "manual" and mirror that. In browsers a manual redirect returns an opaque response you can't read, so it is mostly useful in Node.js.
Pass a JSON string as the body and set the Content-Type header: body: JSON.stringify(data) with headers: { "Content-Type": "application/json" }. fetch() does not serialize objects for you, and without the header many APIs reject the request or read it as plain text.
Pass signal: AbortSignal.timeout(ms) in the options. For curl -m 30 that is AbortSignal.timeout(30000). When the time runs out, fetch() rejects with a TimeoutError. It works in all current browsers and in Node.js 17.3 and later.
Not in a browser. In Node.js you can pass an undici Agent with connect: { rejectUnauthorized: false } as the dispatcher option, which is what the converter generates for -k. Only do this against servers you control, never in production.
Cookie is a forbidden header name, so browsers drop it without an error. Use credentials: "include" to send the cookies the browser already stores for that site. Node.js, Deno and Bun send a Cookie header exactly as written.
No. Parsing and code generation run entirely in your browser. Nothing is uploaded, logged or stored, and the command is cleared when you reload the page.

Last updated by the Playxoft engineering team.

From the engineers who built this tool

Fighting messy data every day?

When payloads, schemas and integrations keep breaking, the fix is usually upstream. We design typed APIs and backends that stay clean as you grow. Tell us what you are building and we will suggest the simplest architecture that fits.

More free tools

See all tools

SQL Formatter

Beautify or minify SQL in 12 dialects, with keyword case, indent and line:column errors.

Open tool

cURL to Python Converter

New

Convert cURL commands into Python requests or httpx code with params, json, files and auth.

Open tool

cURL to Axios Converter

New

Convert cURL commands into an Axios request config with params, data, auth and timeouts.

Open tool

SQL to Prisma Converter

Turn SQL DDL into a schema.prisma with native types, relations and enums.

Open tool

SQL to Drizzle Converter

Turn SQL DDL into a typed Drizzle schema.ts with indexes, enums and relations().

Open tool

SVG to JSX Converter

Turn SVG markup or files into clean React and React Native components.

Open tool