About curl to fetch converter
The fetch API is built into browsers and modern Node.js. Paste a cURL command, such as one copied from your browser's network tab, and get equivalent fetch code.
What is mapped
- -X becomes the method option.
- -H becomes entries in headers.
- -d becomes the body.
After converting
The converter keeps the method, URL, headers and body from your cURL command. Check fetch-specific details such as error handling, timeouts and how secrets such as API keys are stored. Never commit real keys to source control.
A worked example
curl -X POST https://api.example.com/users -H 'Content-Type: application/json' -d '{"name":"Asha"}' becomes fetch('https://api.example.com/users', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'Asha' }) }). Then check response.ok and call response.json().
Differences to remember
- fetch does not throw for HTTP error codes such as 404. Check response.ok.
- Browser requests are limited by CORS, which cURL ignores.
- Cookies need credentials: 'include' in fetch.
