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.
curl https://api.example.com/v1/notes -H 'Content-Type: application/json' -d '{"title":"Groceries","done":false}'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.
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,-bwith name=value cookies,-rand--oauth2-bearerbecome the method and headers.-d,--data-raw,--data-binary,--data-urlencodeand--jsonbecome the body. Several -d parts are joined with &, as curl does.-Fand--form-stringbecome FormData, with file parts read from a file input in the browser or from disk in Node.js and Python.-ubecomes an Authorization: Basic header built with btoa(), or the auth option in axios and Python.-Gmoves the data into the query string,-Isends HEAD,-Tuploads a file with PUT and-mbecomes a timeout.- Short options can be joined, as in
-sSLor-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.
// 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.
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.