Axios Code Generator

Fill in a request and get Axios code that uses the library's own options: params for the query string, auth for basic auth, and data for the body. Axios serialises JSON and sets the header itself, so the generated code stays short. Switch to cURL, fetch() or HTTPie for the same request.

Query parameters
Headers
Authentication
Body
Output

Writing the code runs in your browser. What you type never leaves this device.

This page only writes the code. It never sends your request or sees your token.

Features

  • Uses axios.request with method, url, params, headers and data

  • Query parameters go in params, so Axios encodes them

  • Basic auth written as the auth option, not a hand-made header

  • JSON bodies as plain objects; Axios adds Content-Type: application/json

  • FormData for file uploads and URLSearchParams for urlencoded forms

  • Optional async function wrapper with try and catch

When to reach for Axios code

Projects that already use Axios

Keep new API calls consistent with the rest of the codebase, including interceptors and base URLs you set up.

Node scripts and back-office jobs

Axios works the same in Node and the browser, so one snippet serves a cron job and an admin page.

Porting cURL examples

Copy the method, headers and body from a provider's cURL example into the form and get Axios code back.

How Axios differs from fetch

Errors and response data

  • Axios rejects for any status outside 200 to 299, so a catch block sees 4xx and 5xx. Read error.response.status and error.response.data there.
  • The parsed body is in response.data; there is no separate .json() step.
  • validateStatus in the config changes which statuses count as success.

Bodies

Pass an object as data and Axios sends it as JSON. Pass URLSearchParams for a urlencoded form, or FormData for uploads; Axios sets the matching Content-Type. Only set Content-Type yourself when the API wants something unusual, such as application/vnd.api+json.

Axios Code Generator - FAQ