fetch 과제 의사코드
const newsURL = 'http://localhost:4999/data/latestNews';
const weatherURL = 'http://localhost:4999/data/weather';
function getNewsAndWeather() {
// TODO: fetch을 이용해 작성합니다
1. fetch로 newsURL 가져옴
2. json으로 변환
// TODO: 여러개의 Promise를 then으로 연결하여 작성합니다
3. 체이닝으로 연결하여 fetch로 weatherURL 가져옴
4. json으로 변환
}
if (typeof window === 'undefined') {
module.exports = {
getNewsAndWeather
}
}
function getNewsAndWeatherAll() {
// TODO: Promise.all을 이용해 작성합니다
1. fetch한 newsURL , weatherURL을 promiseAll로 묶습니다
2. 가져온 newsURL , weatherURL을 json으로 변환합니다
3. json으로 변환한 news와 weather를 리턴합니다
};
});
}
if (typeof window === "undefined") {
module.exports = {
getNewsAndWeatherAll,
};
}
async function getNewsAndWeatherAsync() {
// TODO: async/await 키워드를 이용해 작성합니다
1. newsURL의 json을 담을 const를 생성합니다
2. json의 value를 담습니다
3. 반환되는 promise를 await로 대기합니다
4. weatherURL을 2,3 합니다
5. 담은 데이터를 리턴합니다
}
if (typeof window === "undefined") {
module.exports = {
getNewsAndWeatherAsync,
};
}