Fetch API GET Request
Modern Fetch with async/await, response status check, and JSON parsing.
Author:
chris
// Language: JavaScript
async function getZen() {
const res = await fetch('https://api.github.com/zen');
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.text();
}
getZen().then(console.log).catch(console.error);