Axios란?
브라우저와 node.js에서 사용할 수 있는 Promise 기반 HTTP 클라이언트 라이브러리
Axios는 node.js와 브라우저를 위한 Promise 기반 HTTP 클라이언트 입니다. 서버 사이드에서는 네이티브 node.js의 http 모듈을 사용하고, 클라이언트(브라우저)에서는 XMLHttpRequests를 사용합니다.
쉽게 말해서 백엔드랑 프론트엔드랑 통신을 쉽게하기 위해 Ajax와 더불어 사용합니다.
특징
GET / POST / DELETE / UPDATE 예시
// GET
axios.get('/user', {
params: { ID: 12345 }
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
// always executed
});
// POST
axios.post("url", {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {response })
.catch(function (error) {
// 오류발생시 실행
})
// PUT
axios.put("url", {
username: "",
password: "",
})
.then(function (response) {
// response
}).catch(function (error) {
// 오류발생시 실행
})
// DELETE
axios.delete("user?ID=12345")
.then(function (response) {
// hancle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})