Real shell quoting
Commands copied from Chrome, Firefox or API docs, including multi-line ones, parse correctly.
Turn a curl command into ready-to-run JavaScript fetch() code
This tool is completely free — no credits required. All processing happens in your browser.
const response = await fetch("https://api.example.com/v1/messages", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
},
body: JSON.stringify({
"to": "[email protected]",
"subject": "Hello",
"draft": false
}),
});
if (!response.ok) {
throw new Error(`Request failed with status ${response.status}`);
}
const data = await response.text();
console.log(data);API documentation and browser developer tools give you requests as curl commands, but your app needs JavaScript. Rewriting quotes, headers and bodies by hand is slow and easy to get wrong. This converter parses the command the way a shell would and writes the equivalent fetch() call.
The converter reads the command in three passes.
The text is split into words using POSIX shell rules: single quotes are literal, double quotes allow \" and \\ escapes, $'…' strings decode \n and \t, and a backslash at the end of a line joins the next line.
Each option is matched to its fetch() equivalent. -d data is joined with & and labeled application/x-www-form-urlencoded, as curl does; --json adds JSON Content-Type and Accept headers.
-X sets the method explicitly. Otherwise a request with a body becomes POST, -I becomes HEAD, and -G moves the data into the URL's query string and sends GET.
The tool writes a fetch() call with method, headers and body, checks response.ok, and reads the response as JSON when the request accepts JSON.
Commands copied from Chrome, Firefox or API docs, including multi-line ones, parse correctly.
Valid JSON is pretty-printed as an object inside JSON.stringify(), ready to edit.
-F fields become a FormData object; --data-urlencode values are percent-encoded.
-u user:password becomes a Base64 Authorization header, UTF-8 safe.
Options like -k, --proxy or file uploads are listed as not converted, with the reason.
Commands often contain API keys. Conversion happens locally and nothing is uploaded.
Anyone moving an HTTP request from the terminal into JavaScript.
Turn an example from API docs into a fetch() call for a React or vanilla JS app.
Use the built-in fetch() in Node 18 and later without adding an HTTP library.
Reproduce a request copied from the browser's network panel in a test script.
See how each curl option maps to a fetch() option.
In browser developer tools, right-click a request in the Network panel and choose Copy as cURL (bash) for the most accurate input.
Copied requests include headers like sec-ch-ua or Cookie that browsers won't let scripts set. Delete the ones your code doesn't need.
Replace tokens in the generated code with environment variables before committing it.
A request that works in curl can still be blocked in a browser if the server doesn't allow your origin. Server-side fetch() isn't affected.
-X/--request, -H/--header, -d/--data, --data-raw, --data-binary, --data-ascii, --data-urlencode, --json, -F/--form, -u/--user, -G/--get, -I/--head, -A/--user-agent, -b/--cookie, -e/--referer, -m/--max-time and --url. -L, -s, -S, -v, -i, -f and --compressed are recognized and explained.
They are listed under Not converted. Examples are -k (skip TLS checks), --proxy, -o (save to a file) and file uploads with @file. Nothing is dropped silently.
curl sends -d data as application/x-www-form-urlencoded. fetch() would label a string body text/plain, so the header is added to keep the request identical.
fetch() already asks for compressed responses and decompresses gzip, deflate and brotli automatically, so no code is needed.
Yes. fetch() is built into Node.js 18 and later, Deno and Bun. Top-level await needs an ES module or an async function.
No. Parsing and code generation run in your browser and nothing you paste leaves your device.