TIL_Axios

hyemi jo·2020년 11월 29일
0

Axios ?

Axios 는 Promise API 를 활용하는 HTTP 비동기 통신 라이브러리 이다.

설치

npm install axios

or

yarn add 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 () {
    // ...
  });

POST 요청

axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
profile
기억보단 기록을📓

0개의 댓글