티스토리 뷰
axios (액시오스)
Promise based HTTP client for the browser and node.js
- jQuery 를 사용할 때 AJAX 라고 보면 됨
설치
npm install axios
GET 요청
axios 를 사용해 GET 요청 하는 방법
const axios = require('axios');
// ID로 사용자 요청
axios.get('/user?ID=12345')
// 응답(성공)
.then(function (response) {
console.log(response);
})
// 응답(실패)
.catch(function (error) {
console.log(error);
})
// 응답(항상 실행)
.then(function () {
// ...
});
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
// ...
});
POST 요청
axios를 사용해 POST 요청하는 방법
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
멀티 요청
여러 개의 요청을 동시 수행할 경우 axios.all() 메서드 사용
function getUserAccount() {
return axios.get('/user/12345');
}
function getUserPermissions() {
return axios.get('/user/12345/permissions');
}
axios.all([getUserAccount(), getUserPermissions()])
.then(axios.spread(function (acct, perms) {
// Both requests are now complete
}));
- 더 많은데 여기까지만 보고 나머지는 필요할때 사이트 추가적으로 봐야할듯
※ 출처
'JavaScript & TypeScript' 카테고리의 다른 글
Next export 시 Image Optimization 설정 문제 (3) | 2022.01.03 |
---|---|
TypeORM synchronize true 시 이전 table 까지 생성 문제 (2) | 2021.12.26 |
react-router-dom (0) | 2020.12.13 |
create-react-app :: NPM, NPX (0) | 2020.12.13 |
React - LifeCycle API (0) | 2020.11.24 |
링크
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 프로그래머스 SQL
- js array
- JS 딥다이브
- HTTP 완벽 가이드
- 드림코딩
- 김영한 JPA
- 백기선 스터디
- GCP
- HTTP 완벽가이드
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- js promise
- 프로그래머스
- 김영한 http
- dreamcoding
- 이펙티브자바 스터디
- REST API
- JPA 연관관계 매핑
- 이펙티브자바 아이템60
- js api
- 패스트캠퍼스 컴퓨터공학 완주반
- 킹수빈닷컴
- Spring Security
- 모던자바스크립트
- 이펙티브자바
- BOJ
- 이펙티브자바 아이템59
- 백준
- ㅇㄷㅇㅈ
- java
- http
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
글 보관함