Skip to content

curl to fetch and axios converter

Paste a curl command and get the same request as JavaScript fetch and axios code. Useful when you copy a request out of Chrome DevTools or a README into real code.

Why convert curl?

curl is the common language of API documentation. Every vendor README, every OpenAPI doc and every Chrome DevTools "Copy as cURL" gives you a curl command. But your app is JavaScript, and turning a curl line into fetch or axios by hand takes care: pick the right method, move the headers into the right shape, parse the body, and escape the quotes correctly.

This tool does the conversion for you. Paste curl at the top and get fetch and axios below. Edit the curl and the outputs update live.

When to use this tool

  • Repeating a Chrome DevTools request. Right-click the request in the Network tab, choose "Copy as cURL" and paste it here. The fetch or axios output goes straight into your code.
  • Following an API quickstart. The vendor docs show curl and you are writing TypeScript. Convert once and carry on.
  • Testing an idea. Have a curl that works? Convert it to fetch, paste it into the browser console, and see if CORS lets it through.

What is supported

  • -X / --request METHOD
  • -H / --header "Key: Value" (repeatable)
  • -d / --data / --data-raw / --data-binary (body; more than one is joined with &)
  • --data-urlencode (treated as body, not encoded)
  • -u / --user user:pass (becomes Authorization: Basic ...)
  • -G / --get (forces GET, moves the body to the query string)
  • --compressed, -i, -s, -L (ignored, they do not change the request)
  • A \ at the end of a line, as in the sample, joins the lines.

What is not supported yet

  • -F / --form (multipart). It maps to FormData in fetch and a multipart config in axios.
  • --upload-file. Same as -F.
  • --cookie-jar and similar flags. The browser manages cookies; you usually do not pass them yourself.
  • Bash heredocs and environment variables ($TOKEN). Replace these with real values before pasting.

Other long flags (starting with --) are skipped together with the value after them.

Worked examples

  • Bearer token and 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 the body JSON.stringify({"name": "foo"}). The axios output passes the same object as data.
  • Basic auth. curl -u alice:secret https://api.example.com/me becomes a GET fetch with Authorization: Basic YWxpY2U6c2VjcmV0.
  • Query parameters. curl -G https://api.example.com/search --data-urlencode "q=tenali ramakrishna" becomes a fetch to https://api.example.com/search?q=tenali ramakrishna, and an axios call with params: { "q": "tenali ramakrishna" }. The fetch URL is not percent-encoded, so change the space to %20 before you use it, or let axios encode the params.

FAQ

Which curl flags does this tool support?

-X / --request, -H / --header, -d / --data / --data-raw / --data-binary / --data-urlencode, -u / --user, -G, --compressed, -i, -s, -L. Other long flags are skipped.

Are multipart and file uploads supported?

Not yet. -F (multipart form data) and --upload-file are not supported. They map to FormData in fetch and to multipart configs in axios.

What happens to -u and Basic auth?

It becomes an Authorization: Basic <base64> header in the output, the same header curl itself sends.

Why is my body output a JSON.stringify call?

When the request body parses as JSON, the fetch output writes it as a JS object inside JSON.stringify, so you can edit it in code. Axios takes the object directly in the data option.

Does the output run as it is in a browser?

Yes, as long as the API allows your origin through CORS. If it does not, run the request from your server-side code, in Node, or through a proxy.