axios

지영·2022년 10월 23일
0
post-thumbnail

다양한 Axios 응용 메소드

axios all

여러 개의 요청을 동시 수행할 경우 axios.all() 메서드를 사용한다고 한다.

이 때 response는 axios.spred의 콜백함수의 인자로 순차적으로 들어가기 때문에 response에 대한 처리는 axios.spread의 콜백함수 내부에서 할 수 있다.

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
  }));

axios create

custom 속성을 지닌 axios 만의 instance를 만들 수 있다.

const instance = axios.create({
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  headers: {'X-Custom-Header': 'foobar'}
});

profile
천천히 운영되는 개발 블로그

0개의 댓글