16 lines355 B
async function forecast(city) { | |
const res = await fetch(`/api/weather?city=${encodeURIComponent(city)}`); | |
if (!res.ok) throw new Error(`HTTP ${res.status}`); | |
return res.json(); | |
} | |
| |
async function main() { | |
try { | |
const f = await forecast("Lisbon"); | |
console.log(f.temperature); | |
} catch (err) { | |
console.error(err.message); | |
} | |
} | |
| |
main(); |