Skip to content

cURL to Axios Converter

Convert a cURL command to Axios request code — config object, headers, JSON or form body and basic auth mapped automatically. Runs entirely in your browser.

cURL command

bash syntax

Axios

request.js

Paste a command to see the generated code.

Parsing and code generation happen in your browser. Tokens and credentials inside the command are never transmitted.

About the cURL to Axios Converter

Paste a cURL command and get the equivalent Axios request — method, URL, headers, body and basic auth mapped onto a single config object. It is the fastest way to turn an API's documentation snippet, or a Copy as cURL paste from DevTools, into code you can drop into a service file.

The output uses the config-object form, `axios({ method, url, ... })`, rather than the shorthand `axios.post(url, data, config)`. The shorthand reads well until a request has both a body and headers, at which point the argument order becomes a common source of bugs. One object keeps every part of the request visible and reorderable.

Two behavioural differences between curl and Axios are handled explicitly rather than silently. Axios follows redirects by default and curl does not, so `maxRedirects: 0` is emitted unless the command passed `-L`. And Axios already throws on a 4xx or 5xx response, so no status check is added — unlike the fetch converter, which has to add one.

  • JSON bodies become an editable object literal passed as `data`, not an escaped string
  • Basic auth mapped to the `auth: { username, password }` object instead of a hand-built header
  • Form bodies converted to URLSearchParams, `-F` uploads to FormData
  • `maxRedirects` set to match what curl actually did
  • `--insecure` explained with the Node `httpsAgent` equivalent rather than dropped
  • Runs as one shared converter with the fetch, Python and Node targets — switch tabs without losing the pasted command

How to use it

  1. Copy a cURL command — from an API's docs, your shell history, or Copy as cURL (bash) in browser DevTools.
  2. Paste it into the left pane. Multi-line commands with backslash continuations work as-is.
  3. Read the generated Axios code on the right; it updates as you type.
  4. Install the dependency with `npm install axios` if the project does not already have it.
  5. Move any token or password out of the snippet and into an environment variable before committing it.

Real-world use cases

Frontend & full-stack developers

Turn the cURL example in a third-party API's docs into the Axios call that fits straight into an existing service module, instead of hand-translating headers and a JSON body by eye.

Backend & Node.js developers

Convert a support engineer's curl repro of a failing request into an Axios call that reproduces it in code, with the same headers, body and auth, for a script or an integration test.

QA & test automation engineers

Turn a captured request from a bug report or a HAR entry into an Axios call inside a Jest, Vitest or Playwright test, rather than re-deriving the request shape by hand.

Mobile & React Native developers

Axios is the common HTTP client in React Native, where the fetch API's error handling is thinner than on the web. Convert a vendor's curl example straight to the client already used in the app.

DevOps & platform engineers

Turn a curl health-check or webhook call documented in a runbook into a short Axios script, complete with the auth object and maxRedirects setting the original command implied.

Examples

A JSON POST

Input
curl -X POST https://api.example.com/users \
  -H 'Content-Type: application/json' \
  -d '{"name":"Ada","active":true}'
Output
import axios from "axios";

const payload = {
  "name": "Ada",
  "active": true
};

const response = await axios({
  method: "post",
  url: "https://api.example.com/users",
  headers: {
    "Content-Type": "application/json",
  },
  data: payload,
  maxRedirects: 0,
});

console.log(response.data);

The body is a real object, so you can edit a field without fighting escaped quotes. Axios serialises it and sets Content-Type itself.

Basic auth

Input
curl -u ada:hunter2 https://api.example.com/me
Output
import axios from "axios";

const response = await axios({
  method: "get",
  url: "https://api.example.com/me",
  auth: {
    username: "ada",
    password: "hunter2",
  },
  maxRedirects: 0,
});

console.log(response.data);

Axios base64-encodes the credentials for you. Building the Authorization header by hand is a common way to get the encoding wrong.

A form POST

Input
curl -X POST https://api.example.com/login -d 'user=ada&pass=secret'
Output
import axios from "axios";

const payload = new URLSearchParams({
  "user": "ada",
  "pass": "secret",
});

const response = await axios({
  method: "post",
  url: "https://api.example.com/login",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded",
  },
  data: payload,
  maxRedirects: 0,
});

console.log(response.data);

Passing URLSearchParams rather than a plain object is what makes Axios send a urlencoded body instead of JSON.

Common errors

MessageCauseFix
Request body is empty on the serverA plain object was passed as `data` for a urlencoded endpoint. Axios serialises plain objects as JSON.Wrap the fields in `new URLSearchParams({...})`, which is what this converter emits for a `-d` body.
Multipart request rejected / boundary not foundA `Content-Type: multipart/form-data` header was set manually, overwriting the boundary Axios generates.Delete the Content-Type header and let the FormData serializer set it. The converter already omits it.
Request unexpectedly succeeds after a redirectAxios follows up to 5 redirects by default; curl without `-L` stops at the 301 or 302.Keep the generated `maxRedirects: 0` if you want the exact behaviour the curl command had.
AxiosError: Request failed with status code 404Not a bug — Axios rejects the promise for any status outside 2xx, which is the opposite of fetch.Catch it, or set `validateStatus` if you need to inspect a 4xx response body yourself.
self signed certificate in certificate chaincurl's `-k` was in the command. TLS verification cannot be disabled from the browser at all.On Node, pass `httpsAgent: new https.Agent({ rejectUnauthorized: false })`. Never do this against production.

Frequently asked questions

Is my cURL command sent anywhere?

No. Parsing and code generation both run in your browser as you type. Bearer tokens, cookies and passwords inside the command never leave the page, and nothing is logged or stored.

Why the config object instead of axios.post(url, data)?

The shorthand takes data as the second argument and config as the third, which is easy to get wrong once a request has both a body and headers — and silently sends your headers as the body. One config object makes every part of the request explicit and is what the Axios documentation uses for non-trivial requests.

Why is maxRedirects set to 0?

curl does not follow redirects unless you pass -L, but Axios follows up to five by default. Emitting maxRedirects: 0 keeps the generated request faithful to the command you pasted. If the command had -L, the option is left out so the Axios default applies.

Do I need a try/catch or a status check?

A try/catch, if you want to handle failures. Axios throws on any non-2xx status by default, so there is no equivalent of fetch's response.ok check to add — that difference is the single most common bug when porting between the two libraries.

Does this work with a Copy as cURL paste from DevTools?

Yes, that is the main case it is built for. The parser is shell-aware: it handles backslash line continuations, single and double quoting, and ignores presentation-only flags like --compressed.

What happens to a file upload?

A -F field with an @filename becomes a commented-out form.append line naming the original file. The browser cannot read a path off your disk, so the line is left for you to wire up to a file input or a Node read stream.

Does the generated code use async/await?

Yes — `const response = await axios({ ... })`. Paste it inside an async function, or at the top level of an ESM file that supports top-level await. To use it in a plain script instead, wrap the axios(...) call in .then(response => ...) or drop the await and handle the returned promise directly.

Can I convert several cURL commands at once?

No — one command per conversion. Paste commands one at a time; each replaces the previous output. If your API docs list several example requests, converting them individually also makes it easier to check each one before it goes into your code, rather than reviewing a large generated block at once.

Last updated