cURL to Fetch / Axios Converter
Paste a curl command from API docs, Postman or your browser's DevTools and get equivalent JavaScript using fetch() or Axios — headers, request body, authentication and query parameters included.
Works with commands copied from browser DevTools (“Copy as cURL”, bash or cmd), API docs and Postman. Nothing is sent anywhere.
JavaScript fetch
const res = await fetch("https://api.example.com/v1/orders", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_TOKEN",
},
body: JSON.stringify({
"product_id": 42,
"quantity": 2
}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.text(); // or res.json()
console.log(data);From a curl example to working JavaScript
API documentation almost always shows requests as curl commands, and browser DevTools can copy any network request as curl. Translating those commands into JavaScript by hand means carefully moving every header, body and flag into a fetch() options object — and it’s easy to miss the one detail that makes the request fail. This converter parses the command and writes the equivalent fetch() or Axios code for you.
How to use it
- Paste a curl command. Multi-line commands with backslashes (bash) or carets (Windows cmd) are fine.
- Choose fetch with async/await, fetch with .then(), or Axios.
- Check the parsed method, URL and header count, plus any warnings about options that can’t be translated.
- Copy the code into your project and replace placeholders such as API keys.
To grab a request from a website, open DevTools, go to the Network tab, right-click the request and choose Copy → Copy as cURL.
What gets converted
- Method — from -X, or inferred: requests with data become POST, and -I becomes HEAD.
- Headers — every -H, plus -A (User-Agent), -e (Referer) and -b (Cookie).
- Body — -d, --data-raw, --data-binary and --data-urlencode. JSON bodies are pretty-printed and wrapped in JSON.stringify() for fetch, or passed as an object to Axios.
- JSON shortcut — --json sets the body plus JSON Content-Type and Accept headers, like curl does.
- Forms — -F fields become a FormData object; file fields are marked for you to attach a File.
- Auth — -u user:password becomes an Authorization: Basic header for fetch, or Axios’s auth option.
- Query strings — with -G, data is appended to the URL instead of sent as a body.
Things to know
curl sends -d data as a URL-encoded form unless you set a Content-Type, so the converter adds that header to keep the behaviour identical. Options such as -k (skip certificate checks) have no browser equivalent and are listed as warnings. When running the code in a browser, the API must allow your site’s origin through CORS; server-side JavaScript doesn’t have that restriction.
The command is parsed entirely in your browser, so tokens and API keys in it aren’t sent anywhere. Still, remove real credentials before sharing code or committing it.
Generate types for the response with the JSON to TypeScript Converter, format responses with the JSON Formatter, and inspect bearer tokens with the JWT Decoder.
Frequently asked questions
Which curl options are supported?
The common ones: -X/--request, -H/--header, -d/--data and its variants (--data-raw, --data-binary, --data-urlencode), --json, -F/--form, -u/--user, -G/--get, -I/--head, -A, -e, -b, and --url. Options that don't apply to browsers, such as --compressed and -k, are noted or ignored.
Can I paste a command copied from Chrome DevTools?
Yes. In the Network tab, right-click a request and choose Copy → Copy as cURL (bash) or (cmd). Both formats are supported, including Windows ^ escaping and line continuations.
Why does curl -d send form data?
Without a Content-Type header, curl sends -d data as application/x-www-form-urlencoded. The converter adds that header so the JavaScript request behaves the same. Use --json or a JSON Content-Type header to send JSON.
Will the generated fetch code work in the browser?
The request will be identical, but browsers enforce CORS: the API must allow requests from your site's origin. Server-side code (Node.js, Next.js API routes) isn't affected by CORS.
Are my API keys safe?
The command is converted entirely in your browser and never sent anywhere. Still, avoid sharing real tokens in code you publish.