cURL to JavaScript fetch converter
Copy a request from developer tools or API docs and get fetch code that runs in browsers and Node.js 18+.
Loading the tool…
Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.
How to use it
- Enter curl command.
- The result appears straight away and updates as you edit.
- Copy the result, or copy a link that keeps the same values to share it.
How it is calculated
The command is split the way bash does it (single and double quotes, $'' and trailing \), then -X, -H, -d, --data-raw, --data-binary, --data-urlencode, --json, -F, -u, -A, -e, -b, -G and -I are read. With -d, Content-Type: application/x-www-form-urlencoded is added as curl does, and -u becomes a Basic header in Base64.
Example
Result: fetch code: const response = await fetch('https://api.example.com/v1/orders', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer TOKEN' }, body: '{"product":"oud","qty":2}' });; Method: POST; Notes: No notes.
curl -X POST 'https://api.example.com/v1/orders' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer TOKEN' \
-d '{"product":"oud","qty":2}'const response = await fetch('https://api.example.com/v1/orders', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer TOKEN'
},
body: '{"product":"oud","qty":2}'
});Limits and caveats
- Browsers block headers such as Cookie, Host and Referer in fetch; they work in Node.js.
- Reading @file, $VAR variables and Windows cmd syntax are not supported.
- curl follows redirects only with -L, while fetch follows them by default.
Questions about this tool
How do I copy a request as curl?
In the Network tab, right-click the request and choose Copy, then Copy as cURL (bash).
Why was a Content-Type header added that I did not write?
curl sends application/x-www-form-urlencoded with -d automatically while fetch would send text/plain, so it is added to match what curl sends.
What do the notes under the code mean?
They list options that were left out because they do not change the request or have no fetch equivalent, such as -o and -k.
