curl to fetch and axios converter
Paste a curl command and get the equivalent JavaScript fetch and axios snippets. Handy when copying a request out of Chrome DevTools or a README into actual code.
curl
fetch
axios
Why convert curl?
curl is the universal language of API documentation. Every vendor README, every OpenAPI doc, every Chrome DevTools "Copy as curl" gives you a curl command. But your app is JavaScript, and translating a curl line into fetch or axios by hand is fiddly: pick the right method, move headers into the right shape, parse the body, escape the quotes correctly.
This tool does the translation for you. Paste curl on the left, get fetch and axios on the right. Edit the curl and the outputs update live.
When to use this tool
- Reproducing a Chrome DevTools request.Right-click the request in the Network tab, "Copy as cURL", paste it here. The fetch / axios output drops straight into your code.
- Following an API quickstart.The vendor's docs show curl. You're writing TypeScript. Convert once, keep moving.
- Testing a hypothesis.Got a working curl? Convert to fetch, paste into the browser console, see if CORS lets it through.
What's supported
-X / --request METHOD-H / --header "Key: Value"(repeatable)-d / --data / --data-raw / --data-binary(body)--data-urlencode(treated as body)-u / --user user:pass(becomesAuthorization: Basic ...)-G / --get(forces GET, moves body to query string)--compressed,-i,-s,-L(silently ignored)
What's not supported (yet)
-F / --form(multipart). Maps toFormDatain fetch, multipart config in axios. Coming in a follow-up.--upload-file. Same as-F.--cookie-jarand friends. Cookies are managed by the browser; you typically don't pass them explicitly.- Bash heredocs, environment variables (
$TOKEN). Replace these with literal values before pasting.
Worked examples
- Bearer token + JSON body.
curl -X POST https://api.example.com/items -H "Authorization: Bearer abc" -H "Content-Type: application/json" -d '{"name":"foo"}'becomes a fetch with the headers object, method POST, and bodyJSON.stringify({name:"foo"}). - Basic auth.
curl -u alice:secret https://api.example.com/mebecomes a fetch withAuthorization: Basic YWxpY2U6c2VjcmV0. - Query parameters.
curl -G https://api.example.com/search --data-urlencode "q=tenali ramakrishna"becomes a fetch with the URL?q=tenali%20ramakrishna.