[개발] - Front/Mega-JavaScript
API 호출하기
완벽한 장면
2024. 4. 14. 20:28
API란?
예시
let response = fetch("https://jsonplaceholder.typicode.com/posts").then((res) => {
console.log(res);
})
조금 더 세련되게 json 형식으로 가져와보겠다.
async function getData() {
let rawResponse = await fetch("https://jsonplaceholder.typicode.com/posts");
let jsonResponse = await rawResponse.json(); // json 형태로 반환
console.log(jsonResponse);
}
getData();
728x90
반응형