대표적인 비동기 요청으로는 네트워크 요청이 있고, 그 중 URL 요청이 흔하다.
fetch API는 URL 요청을 가능하게 해주는 API이다. (web API)
브라우저에서 사용되며 특정 URL로부터 정보를 받아오는 일을 한다.
fetch는 promise를 return한다.
//1
fetch(URL)
.then(response => response.json())
.then(...불러온 data에 대해 할 일...)
//2
fetch(URL1)
.then(response => response.json())
.then(data1 => // json에 대해 할 일
return fetch(URL2)
.then(response => response.json())
.then(data2 => {
return {data1, data2}
})
})
}