네트워크 요청

dice0314·2023년 5월 17일
0

fetch API

  • 웹 브라우저에 내장된 JavaScript API
  • 서버와 네트워크 통신을 하여 데이터를 가져오거나 전송할 수 있게 해준다.
// 지정한 경로(URL)의 데이터를 주고받을 수 있다.
fetch('https://www.naver.com/data')
  // .json()은 서버에서 받아온 데이터를 자바스크립트 객체로 변환해준다.
  .then(response => response.json())

Axios

  • JavaScript에서 HTTP 요청을 보내는 기능을 제공하는 라이브러리
  • 브라우저와 Node.js 환경에서 사용할 수 있다.

Axios 설치 명령어

npm install axios

Axios의 주요 요청메소드

1. GET 요청

axios.get(url)
  .then(response => {
    // ...
  })

2. POST 요청

axios.post(url, data)
  .then(response => {
  	// ...
  })

3. PUT 요청

axios.put(url, data)
    // ...
  })

4. DELET 요청

axios.delete(url)
  .then(response => {
    // ...
  })

5. PATCH 요청

axios.patch(url, data)
  .then(response => {
    // ...
  })
profile
정리노트

0개의 댓글