2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00
Files
axios/docs/pages/getting-started/first-steps.md
T
Jay 13fdbec872 chore: docs and post release improvements (#10841)
* chore: update changelog and update gitignore

* chore: update PR and issue templates

* chore: updated docs

* chore: update all docs to match

* chore: update both files to match

* chore: remove un-needed yml

* Update docs/fr/pages/advanced/error-handling.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Update docs/es/pages/advanced/x-www-form-urlencoded-format.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Update docs/pages/advanced/error-handling.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Update docs/es/pages/advanced/error-handling.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Update docs/pages/advanced/x-www-form-urlencoded-format.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Update docs/zh/pages/advanced/x-www-form-urlencoded-format.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Update docs/zh/pages/advanced/request-config.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Update docs/zh/pages/advanced/request-config.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Update docs/pages/advanced/request-config.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Update docs/fr/pages/advanced/x-www-form-urlencoded-format.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Update docs/zh/pages/advanced/error-handling.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Update docs/zh/pages/advanced/request-config.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2026-05-04 19:57:05 +02:00

3.7 KiB

First steps

Welcome to the axios documentation! This guide will help you get started with axios and make your first API request. If you're new to axios, we recommend starting here.

Installing

You can use axios in your project in a few different ways. The most common way is to install it from npm and include it in your project. But we also support jsDelivr, unpkg, and more.

Using npm

npm install axios

Using pnpm

pnpm install axios

Using yarn

yarn add axios

Using bun

bun add axios

Using deno

deno install npm:axios

Using jsDelivr

When using jsDelivr we recommend using the minified version as well as pinning the version number to avoid unexpected changes. If you would like to use the latest version you can do so by dropping the version number. This is strongly discouraged for production use as it can lead to unexpected changes in your application.

<script src="https://cdn.jsdelivr.net/npm/axios@<x.x.x>/dist/axios.min.js"></script>

Using unpkg

When using unpkg we recommend using the minified version as well as pinning the version number to avoid unexpected changes. If you would like to use the latest version you can do so by dropping the version number. This is strongly discouraged for production use as it can lead to unexpected changes in your application.

<script src="https://unpkg.com/axios@<x.x.x>/dist/axios.min.js"></script>

Importing axios

Once installed, you can import the library using either import or require:

import axios, { isCancel, AxiosError } from "axios";

You can also use the default export, since the named export is just a re-export from the axios factory:

import axios from "axios";

console.log(axios.isCancel("something"));

If you use require for importing, only the default export is available:

const axios = require("axios");

console.log(axios.isCancel("something"));

For some bundlers and ES6 linters you may need:

import { default as axios } from "axios";

For custom or legacy environments where module resolution misbehaves, you can import the prebuilt bundle directly:

const axios = require("axios/dist/browser/axios.cjs"); // browser CommonJS bundle (ES2017)
// const axios = require("axios/dist/node/axios.cjs"); // node CommonJS bundle (ES2017)

Making your first request

An axios request can be made in as few as two lines of code. Making your first request with axios is very simple. You can make a request to any API by providing the URL and method. For example, to make a GET request to the JSONPlaceholder API, you can use the following code:

import axios from "axios";

const response = await axios.get(
  "https://jsonplaceholder.typicode.com/posts/1"
);

console.log(response.data);

axios provides a simple API for making requests. You can use the axios.get method to make a GET request, the axios.post method to make a POST request, and so on. You can also use the axios.request method to make a request with any method.

::: tip Set a timeout in production Without a timeout, a stalled request can hang indefinitely. Pass one via the request config:

const response = await axios.get("https://example.com/data", {
  timeout: 5000, // 5 seconds
});

See timeout in the request config and Error handling for the matching ECONNABORTED / ETIMEDOUT codes. :::

Next steps

Now that you've made your first request with axios, you're ready to start exploring the rest of the axios documentation. You can learn more about making requests, handling responses, and using axios in your projects. Check out the rest of the documentation to learn more.