Free tool
curl to JavaScript
Paste a curl command and get the same request in JavaScript with fetch, built into Node 18 and newer, Deno, Bun and every browser. No account; the command is only read.
An example: a POST with JSON and a token
curl -X POST 'https://api.example.com/items?page=1' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-d '{"name":"pen","price":2.5}'becomes, in JavaScript:
JavaScript
const response = await fetch("https://api.example.com/items?page=1", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_TOKEN",
},
body: "{\"name\":\"pen\",\"price\":2.5}",
});
console.log(response.status);
console.log(await response.text());
About the JavaScript code
The code uses fetch, so it needs no package. It runs as it is in an ES module or any place where top-level await works; elsewhere, put it in an async function.
Headers become the headers object and the body is passed as a string. In a browser, a request to another site works only if that site allows it (CORS); from a server there is no such limit.
response.status is the site's status; await response.text() reads the page, await response.json() parses JSON.
What the converter understands
The address, -X, -H, -d and its variants, --json, -u, -A, -b, -e, -G and -I, quotes and lines continued with a backslash. Options that do not change the request, such as -L, -s or --compressed, are ignored.
Other languages
curl to Python, curl to PHP, curl to Go, curl to Java, or all eight languages at once.
Need pages for a program, not code? gimmepage fetches any public page in one request: 1 credit a page, failed requests free.