Skip to content

cURL to Axios

Convert a curl command into an Axios request call, with headers, query params, body and basic auth carried over, live in your browser.

Generated files

Generated code appears here.

Diagnostics appear here after you paste your input.

Processed locally in your browser. Your data never leaves your device.

About this curl to Axios converter

Paste a curl command and get an Axios request call: method, URL, query parameters, headers, body and basic auth carried over exactly, using Axios's own params and auth options rather than reimplementing them by hand. This page is the Axios output of the cURL to Code studio; fetch, Laravel Http and Guzzle are one click away and use the same parsing.

A worked example

This curl command:

curl 'https://api.example.com/v1/users?active=true' \
  -H 'accept: application/json' \
  -H 'content-type: application/json' \
  -H 'authorization: Bearer abc.def.ghi' \
  --data-raw '{"name":"Ada Lovelace","role":"admin"}'

becomes:

const response = await axios({
    method: "post",
    url: "https://api.example.com/v1/users",
    params: {
        active: "true",
    },
    headers: {
        accept: "application/json",
        "content-type": "application/json",
        authorization: "Bearer abc.def.ghi",
    },
    data: "{\"name\":\"Ada Lovelace\",\"role\":\"admin\"}",
})

Note that active=true moved from the URL into params, and the method is lowercased to match Axios's own convention. Turn off the Await option for a plain axios(...).then(...) promise instead.

How to use it

  1. Paste a curl command, drop a file, or load an example.
  2. Choose whether the call should be awaited.
  3. Copy or download the generated file.

Frequently asked questions

Why is the query string in a separate params option instead of the URL?
Axios has a params option built for exactly this: it keeps the base URL readable and lets Axios handle the encoding. The generated code uses it whenever curl's URL had a query string, rather than appending the same text to the URL by hand.
Why is basic auth an auth object instead of a header?
curl's -u/--user sends an Authorization: Basic ... header, but Axios's own auth: { username, password } option produces the identical header while staying readable and easy to change later, so that's what's generated instead of a raw header string.
Does it use axios.get/axios.post or the config-object form?
The config-object form (axios({ method, url, ... })), since it reads the same regardless of method and needs no special-casing for a method curl used that Axios does not have a shorthand for.