How the curl to fetch conversion works
Each curl flag maps onto the fetch API: -H flags become keys in the headers object, -d becomes the body (wrapped in JSON.stringify when JSON), and the HTTP method comes from -X or is inferred from the presence of a body.
Example
curl https://api.example.com/tokens \
-H 'Authorization: Bearer sk_123' \
-H 'Content-Type: application/json' \
-d '{"refresh": true}'
becomes:
const url = 'https://api.example.com/tokens';
const payload = {
"refresh": true
};
const options = {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_123',
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
};
const response = await fetch(url, options);
FAQ
Can I get axios code instead?
Yes — pick Node.js · axios in the dropdown, or use the curl to axios page.