서로 다른 어플리케이션(프로그램)이 데이터를 주고 받을 수 있도록 도와주는 인터페이스(매개체)
웹 서비스를 개발할 때 가장 범용적으로 사용되는 API
HTTP프로토콜을 기반으로 동작함
요청하려는 데이터를 http로 시작하는 주소로 표현함
HTTP Method : 서버가 데이터를 어떻게 처리해주었으면 좋겠는지 설정함
https://jsonplaceholder.typicode.com/ 오픈API
Resources 에서 posts 더미데이터 가져오기
let response = fetch('https://jsonplaceholder.typicode.com/posts')
.then((res) => console.log(res));
//fetch는 API호출을 하게 도와주는 내장함수이다.
👉async function getDate(){
let rawResponse = awit fethch('https://jsonplaceholder.typicode.com/posts');
let jsonResponse = await rawRespons.json();
console.log(jsonResponse);
}
getData();
/*promise의 then, async await는 용도는 같지만, 간결성, 에러 핸들링, 에러 위치
확인 측면에서 차이가 있음. 이외에도 async await은 디버그를 할 때
then과 달리 정확한 위치를 지정할 수 있는 장점이 있다.*/
Reference
https://www.udemy.com/course/react-next-master/learn/lecture/39610782#reviews