[항해99] 4/10 WIL (5)

최스탑·2022년 4월 10일
0

[항해99] WIL

목록 보기
5/13

다섯번째 Keyword

  1. Axios
  • Axios란?
    - Axios는 node.js와 브라우저를 위한 Promise기반 HTTP클라이언트이다.
    서버 사이드에서는 네이티브 node.js의 http 모듈을 사용하고, 클라이언트(브라우저)에서는 XMLHttpRequests를 사용한다.
    쉽게 말해 벡엔드와 프론트엔드가 통신을 쉽게 하기 위해 ajax와 더불어 사용한다.

  • 사용방법
    axios 객체는 아래와 같이 간단한 HTTP요청을 할 수 있다.

get : 입력한 url에 존재하는 자원에 요청을 한다.

axios({
  url: 'https://test/api/postList',
  method: 'get',
  data: {
    today : 'sunday'
  }
});

post

axios.post("url주소",{
  data객체
},[,config])

delete
Delete메서드는 서버에 있는 데이터 베이스의 내용을 삭제하는 것을 주 목적으로 하기에 두 번째 인자를 아예 전달하지 않는다.

axios.delete("/example/list/1")
  .then(function(response){
    console.log(response);
  })
  .catch(function(ex){
    throw new Error(ex)
}

patch
서버의 리스트 중 특정 포스트를 수정한다.

axios.patch('/api/data/3', {title: "리액트 어려워"})
.then(res => { console.log(res.data) })
profile
try & catch

0개의 댓글