search

Found

info Overview

Paste a curl command and convert it into JavaScript fetch or axios code. Reads method, headers, JSON body and auth flags, then toggles between both styles.

📘 How to Use

  1. Paste your curl command into the left input box
  2. Select the fetch or axios tab to switch the output style
  3. Read the generated JavaScript in the right output box

curl to fetch/axios Converter

Copied!
Article

curl to fetch/axios Converter | Turn API Requests into JS Code

Drop a curl command you copied from docs, a README, or a Stack Overflow answer and get the equivalent JavaScript fetch or axios call. The tool reads the method, headers, JSON body, and basic auth, then lets you flip between both output styles.

💡 About this tool

API docs and "try it" snippets are almost always written as curl. When you move that into front-end code, you end up hand-mapping -H flags into a headers object, -d into a body, and -u into an Authorization header — a small, repetitive task that is surprisingly easy to get wrong, especially around quoting and the implicit GET-to-POST switch curl applies once a body is present.

This converter parses the common curl options (-X / --request, -H / --header, the -d family, -u / --user, -b / --cookie, -I / --head) and emits matching fetch or axios code. If the body parses as valid JSON it wraps it in JSON.stringify(...); otherwise it keeps it as a raw string. Unknown flags are skipped rather than breaking the parse, so a messy paste still yields usable output.

Everything runs in your browser with plain JavaScript, so the command — including any bearer tokens or internal hostnames — never leaves the page.

🧐 Frequently Asked Questions

Q. When should I pick fetch over axios? fetch is built into the browser and needs no dependency; axios adds conveniences like automatic JSON parsing and interceptors. Generate both and compare them side by side to match your project's conventions.

Q. Does it handle multi-line curl commands with trailing backslashes? Yes. Line continuations (\ at end of line) are joined before parsing, so a nicely formatted command pasted from docs works as-is.

Q. How is -u user:pass translated? For fetch it builds an Authorization header as Basic ${btoa('user:pass')}. For axios it splits the value into an auth: { username, password } object.

Q. What happens to flags the tool doesn't recognize? Unsupported flags are ignored, and the conversion proceeds using the URL plus the options it understands. You can always add the rest by hand afterward.

Q. Are query strings in the URL preserved? Yes. The URL is passed straight through as the first argument to fetch or axios, query parameters included, without being broken apart.

📚 Fun Facts

curl was released by Daniel Stenberg in 1998 and now ships on practically every server and embedded device on the planet — it is one of the most widely deployed pieces of software ever written. The browser fetch API arrived much later, in 2015, as the modern replacement for XMLHttpRequest. Translating a working curl call into front-end code is one of the most common bridge tasks developers hit when moving from "the API responds" to "the UI talks to it," and axios has long filled the gap between the two with its ergonomic config object.