| <colbgcolor=#5A29E4><colcolor=#fff> axios | |
| | |
| 종류 | HTTP/클라이언트 |
| 라이선스 | MIT 라이선스 |
| 언어 | JavaScript |
| 버전 | 1.15.0 |
| 링크 | |
1. 개요
JavaScript용 웹 클라이언트 라이브러리. 원격 데이터를 fetch하는 JavaScript 라이브러리이며 React(라이브러리)와 Vue.js와 같은 현대 웹 환경에서 서버를 비롯한 원격 데이터를 받아오는 fetching을 할 때 이 라이브러리가 흔히 사용되었다.axios의 발음은 외국인들도 가끔 헷갈리기도 하는데 액시오스(IPA: /ˈæksiɒs/)라고 발음하면 된다.[1]
현지시각 2026년 3월 31일, 북한과 관련된 해커들[2]이 공급망 공격으로 소스코드에 원격 접근용 트로이안 악성코드를 심어 놓은 사건이 발생했다. 2026년 axios 공급망 공격 사건 참조.
2. 예시 코드
#!syntax javascript
const axios = require('axios');
// Make a request for a user with a given ID
axios.get('/user?ID=12345')
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
// always executed
});
// Optionally the request above could also be done as
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
// always executed
});
// Want to use async/await? Add the `async` keyword to your outer function/method.
async function getUser() {
try {
const response = await axios.get('/user?ID=12345');
console.log(response);
} catch (error) {
console.error(error);
}
}
3. 장점
- 서버, 클라이언트 모두에서 쓸 수 있다.
- 기피되고 있는 jQuery, deprecated된 request, 웹 표준이지만 undici 이전 최근까지 Node.js 지원이 안 되었던 Fetch API 등 경쟁 라이브러리에 비해 양 플랫폼 모두에서 쉽고 무난하게 사용할 수 있다.