Skip to content
ToolPlankDEV
Developer Tools
100% In-Browser Execution

Updated:

cURL to Fetch Converter

Paste a curl command and get working code as you type. This curl to fetch converter reads Copy as cURL from Chrome and Firefox (bash or cmd), headers, JSON, forms and file uploads, and writes fetch, axios, XMLHttpRequest or Python. Nothing is sent anywhere.

Options:

curl command

Input
0 chars · 0 lines

Code

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Request summary, warnings and ignored options

The method, URL, headers and body of each request appear here, with warnings and any curl option that has no equivalent in the code.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use cURL to Fetch

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste a curl command

    Paste one curl command or several, or open a text, shell or batch file. In Chrome, Edge or Firefox, open the Network tab, right-click a request and choose Copy as cURL; both the bash and the cmd versions work. Example loads a JSON POST, and the sample buttons load a browser copy, a Windows cmd copy, a file upload and a form.

  2. 02

    Pick the output

    Choose browser fetch, Node.js fetch, axios, XMLHttpRequest or Python requests. The code updates as you type. The panel under the result shows the method, URL, headers and body of each request, with warnings and the curl options that have no equivalent.

  3. 03

    Adjust the code style

    Switch between async/await and a .then() chain, write JSON bodies as editable objects or keep the original string, keep or remove headers that browsers block, and turn the status check and the warning comments on or off.

  4. 04

    Copy or download

    Press Copy to paste the code into your project, or Download to save it as request.js, request.mjs or request.py.

How curl to fetch conversion works

A curl command and a fetch call describe the same HTTP request. The URL stays the same, -X sets the method, each -H becomes a header and -d or --data-raw becomes the body. This curl to fetch converter splits the command the way a shell would, reads every option, and writes the request in the language you pick.

Bash
curl https://api.example.com/v1/notes -H 'Content-Type: application/json' -d '{"title":"Groceries","done":false}'
JavaScript
const response = await fetch("https://api.example.com/v1/notes", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    title: "Groceries",
    done: false
  })
});

if (!response.ok) {
  throw new Error(`Request failed with status ${response.status}`);
}

const data = await response.text();
console.log(data);

curl switches to POST when a command has a body, so the code says POST even though the command never used -X. The status check is there because fetch does not treat a 404 or 500 answer as an error by itself.

Copy as cURL from the browser, bash or cmd

Browser developer tools offer two copies. The bash copy uses single quotes, backslash line breaks and $'...' strings for bodies that contain quotes or line breaks. The cmd copy for Windows wraps every value in ^" and escapes special characters with a caret. The tool detects which one you pasted, or you can pick the shell by hand.

A browser copy carries headers that a script in a page is not allowed to set, such as Cookie, Origin, Referer and the Sec-Fetch headers. The browser fetch and XMLHttpRequest outputs leave them out and say so. When a Cookie header was removed, the code asks the browser to send its own cookies with credentials: "include". Node.js and Python keep every header.

Copy all as cURL puts many commands in one paste. Each one becomes its own request with numbered variable names.

Convert curl to axios, XMLHttpRequest or Python

The same command can come out as axios. A JSON body is passed as a plain object, because axios turns objects into JSON on its own, and -u becomes the auth option.

JavaScript
import axios from "axios";

const response = await axios({
  method: "post",
  url: "https://api.example.com/v1/notes",
  headers: {
    "Content-Type": "application/json"
  },
  data: {
    title: "Groceries",
    done: false
  }
});

console.log(response.data);

Python requests output uses json= for JSON bodies, data= for form bodies and files= for uploads. It is the one target that can honor -k (verify=False) and -x (proxies). XMLHttpRequest output suits older code that already uses it.

Which curl options are converted

  • -X, -H, -A, -e, -b with name=value cookies, -r and --oauth2-bearer become the method and headers.
  • -d, --data-raw, --data-binary, --data-urlencode and --json become the body. Several -d parts are joined with &, as curl does.
  • -F and --form-string become FormData, with file parts read from a file input in the browser or from disk in Node.js and Python.
  • -u becomes an Authorization: Basic header built with btoa(), or the auth option in axios and Python.
  • -G moves the data into the query string, -I sends HEAD, -T uploads a file with PUT and -m becomes a timeout.
  • Short options can be joined, as in -sSL or -XPOST. A URL without http:// gets it added, the same way curl treats it.

Options that only change what curl prints, such as -s, -v and -w, are listed as ignored. --compressed is ignored too, because browsers and Node.js decompress responses by themselves.

Warnings you may see

Some curl options have no match in a browser. The tool still writes the code and tells you what changed, both in the panel and as comments above the request.

JavaScript
// Warning: -k cannot be done in a browser. Browsers always check TLS certificates.
// Note: -u became an Authorization: Basic header built with btoa().
const response = await fetch("https://intranet.example.com/report", {
  headers: {
    "Authorization": "Basic " + btoa("alice:s3cret")
  }
});

Other warnings cover a body sent with GET, which fetch refuses; a JSON body sent without a JSON Content-Type; shell variables such as $TOKEN that were not expanded; and header values with characters that fetch cannot send. A user name and password in the URL are moved into a header, because fetch rejects URLs that contain them.

Uploads and files in Node.js

With the Node.js target, files named with @ are read from disk next to your script. Node 18 and later have fetch and FormData built in, so no package is needed.

JavaScript
import { readFileSync } from "node:fs";

const formData = new FormData();
formData.append("title", "Receipt");
formData.append("file", new Blob([readFileSync("scan.pdf")]), "scan.pdf");

const response = await fetch("https://api.example.com/upload", {
  method: "POST",
  body: formData
});

The multipart Content-Type header is never copied over, because FormData writes it with its own boundary. If a JSON body needs escaping before you paste it into a command, the JSON Escape tool helps, and the URL Encode tool handles query values.

Limits and privacy

The tool converts commands; it never runs them and never contacts the URL. It does not read files named with @ or -K, expand shell variables, or follow --next into a second request. curl does not follow redirects unless you pass -L, while fetch, axios and Python follow them by default. To check a Basic auth value by hand, decode it with the Base64 Decode tool, and the User Agent Parser explains a copied User-Agent header.

Everything runs in your browser and nothing you paste is uploaded, as the Privacy Policy describes.

Frequently Asked Questions

Technical Q&A for cURL to Fetch

Common questions about edge cases, character encoding, and privacy guarantees.

Paste the curl command and keep the output on JavaScript fetch. The method, headers, body and auth are written into a fetch call you can copy.

Yes. Pick axios as the output. JSON bodies become plain objects and -u becomes the auth option.

Yes, both the bash and the cmd copies. Headers that browsers do not let scripts set, such as Cookie and Sec-Fetch headers, are removed from browser code and listed in the panel.

Browsers block scripts from setting Cookie. The code uses credentials: "include" instead, so the browser sends its own cookies; choose Node.js or Python to keep the header.

It becomes an Authorization: Basic header built with btoa("user:password"). axios and Python use their own auth options instead.

No. Browsers always check certificates, and Node's fetch has no option for it. Python requests gets verify=False.

No. It only converts the text in your browser and never contacts the URL in the command.

Yes. Pick Python requests as the output to get json=, data= or files= arguments, with auth, timeout, verify and proxies when the command uses them.