cURL to Fetch
Convert a curl command to a JavaScript fetch() call.
Your curl command is converted locally in your browser and never uploaded, but avoid pasting real production tokens or credentials into any tool.
Inspecting an API URL? Try the URL Parser.
About cURL to Fetch
This curl to fetch converter takes a curl command you copied from your terminal, browser DevTools, or API docs and rewrites it as a ready-to-run JavaScript fetch() call. As a curl to fetch converter it parses common flags like -X, -H, -d, --data-raw, --json, -u, -b, and -G, infers the right HTTP method, sets sensible Content-Type headers, and pretty-prints JSON bodies with JSON.stringify. Use it to move a curl request into front-end code, a Node script, or a quick test without hand-translating syntax. It is built for developers, QA engineers, and anyone wiring up API calls who wants a fast curl to javascript translation. The conversion runs entirely in your browser, so the command you paste is processed locally and never leaves your device.
Features
- Parses methods (-X/--request) and infers GET or POST automatically when none is given
- Converts -H/--header flags into a structured fetch headers object
- Handles -d, --data-raw, --data-ascii, --data-binary, and --json request bodies
- Pretty-prints valid JSON bodies with JSON.stringify and adds the matching Content-Type
- Encodes -u/--user basic auth into an Authorization header and maps cookies, user-agent, and referer
- Rewrites -G/--get requests by appending data as a query string
- Warns about flags with no fetch equivalent, like -k, -L, and output-to-file options
- Copy the result or download it as request.js with one click
How to use the cURL to Fetch
- Paste your curl command into the cURL command box.
- Read the generated fetch() equivalent in the output panel on the right.
- Check the warning banner for any flags that were ignored or adjusted.
- Click Copy to grab the fetch code, or download it as request.js.
Example
Input
curl https://api.example.com/users \
-H "Authorization: Bearer TOKEN" \
-d '{"name":"Ada"}'
Output
const response = await fetch("https://api.example.com/users", {
method: "POST",
headers: {
"Authorization": "Bearer TOKEN",
"Content-Type": "application/x-www-form-urlencoded"
},
body: "{\"name\":\"Ada\"}",
});
const data = await response.text();
A -d body defaults to POST with a form-urlencoded Content-Type.
Common errors & troubleshooting
- The output shows "Command should start with curl" or "No URL found in the curl command". — Make sure the pasted text begins with curl and includes a full URL; the converter expects a real curl invocation.
- A JSON body comes out as a form-urlencoded string instead of JSON.stringify. — Send it with --json or add -H "Content-Type: application/json" so the converter knows to wrap valid JSON in JSON.stringify.
- Flags like -k/--insecure or -L/--location seem to disappear. — These have no fetch equivalent; browsers always enforce TLS and follow redirects by default, so the converter notes them as warnings and drops them.
- --data-urlencode values are not re-encoded. — The converter keeps these verbatim and warns you; encode the value yourself if the endpoint needs strict URL encoding.
Frequently asked questions
- What is the cURL to Fetch converter?
- It is an in-browser tool that parses common curl flags including -X, -H, -d and its variants, --json, -u, -b, -A, -e, -G, and --url, then builds an equivalent JavaScript fetch() call with the right method, headers, and body.
- How do I convert a curl command to fetch?
- Paste your curl command into the input box and the cURL to Fetch converter instantly renders the fetch() equivalent on the right, which you can copy or download as request.js.
- How does the cURL to Fetch converter decide the HTTP method?
- If you pass -X or --request it uses that; otherwise it defaults to POST when a data body is present and GET when there is none.
- Does it handle basic auth from -u and -G query data?
- Yes. A -u or --user value is base64-encoded into an Authorization: Basic header, and with -G your -d data is appended to the URL as a query string while the request body stays empty, just like curl.
- Is my curl command sent anywhere when I convert it?
- No. The curl to fetch conversion runs entirely in your browser, so the command and any tokens in it are processed locally and never leave your device.
Related tools
All ArrayKit tools