[JS] API호출

짱효·2023년 11월 2일

JS

목록 보기
18/21

✏️API




  • API 호출은 서버에게 데이터를 받기위함이다.
  • 응답을 언제 받을지 모름..
  • 그래서 promise로 비동기 하는것임.

API 호출하기

//fetch 호출하는 거 도와주는 내장함수
let response = fetch("https://jsonplaceholder.typicode.com/posts").then((res) =>
  console.log(res)
);

  • 데이터값 출력 함수
async function getData() {
  //fetch 호출하는 거 도와주는 내장함수
  let rawResponse = await fetch("https://jsonplaceholder.typicode.com/posts");
  let jsonResponse = await rawResponse.json();
  console.log(jsonResponse);
}
getData();

profile
✨🌏확장해 나가는 프론트엔드 개발자입니다✏️

0개의 댓글