Convert cURL to Fetch
Turn a cURL command from API docs, Postman, or your shell history into an equivalent JavaScript fetch call, keeping the method, headers, and JSON body intact.
Open the tool, then paste the sample input below. Everything runs locally in your browser.
The problem
Translating cURL by hand drops headers, mishandles the JSON body, or leaks shell quoting into JavaScript. The converter parses the command and produces a fetch call with the right method, headers object, and a JSON.stringify-ed body.
Sample input
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-H "Authorization: Bearer example_token" \
-d '{"name":"Asha","role":"admin"}'
Expected output
await fetch("https://api.example.com/users", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer example_token"
},
body: JSON.stringify({
name: "Asha",
role: "admin"
})
});
The JSON sent with -d becomes a JSON.stringify body, and each -H header becomes an entry in the headers object.
How to do it
- Paste the cURL command into the converter.
- Choose JavaScript Fetch output if the tool offers output options.
- Review the method, URL, headers, and body.
- Copy the generated fetch code.
- Replace placeholder tokens before using it in your app.
Common mistakes
- Forgetting
JSON.stringifyon an object body. - Dropping the
Content-Typeheader. - Losing the Authorization header during translation.
- Pasting shell escaping (backslashes, single quotes) into JavaScript.
- Embedding real tokens in front-end code.
Related tools
Related guides
FAQ
How do I convert cURL to JavaScript fetch?
Paste the cURL command into the converter and select fetch output. It maps the method, headers, and body into a fetch call.
Does fetch support request headers?
Yes. Pass a headers object in the second argument, for example { headers: { "Content-Type": "application/json" } }.
How do I send JSON with fetch?
Set Content-Type to application/json and pass body: JSON.stringify(payload).
Should I put API secrets in browser JavaScript?
No. Anything in front-end code is visible to users. Keep secrets on a server or proxy and call your own backend instead.
Why does my converted fetch request fail CORS?
CORS is enforced by the browser based on the server's response headers. Converting cURL does not change that; the API must allow your origin.
Conversion runs locally in your browser — the cURL command is parsed client-side and never uploaded.