$ js modulo_3
Fetch API e JSON
Busque dados de APIs, trate erros e atualize a interface com async/await.
O que você vai aprender
- fetch e async/await
- response.json()
- Status HTTP e erros
- Loading e estado vazio
1. Requisição
async function carregar() {
const res = await fetch("https://jsonplaceholder.typicode.com/posts/1");
if (!res.ok) throw new Error("HTTP " + res.status);
return await res.json();
}
DICA Use APIs públicas de teste no início.