fetch JSON
async/await com checagem de ok.
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 com checagem de ok.
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.