fetch JSON
async/await with an ok check.
async function getJson(url) {
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
}
Copie o snippet e adapte. Pratique nos exemplos de JavaScript.
async/await with an ok check.
async function getJson(url) {
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
}
Copie o snippet e adapte. Pratique nos exemplos de JavaScript.