Async / Await with Real APIs
async/await wraps Promises so you can write sequential code that waits on network I/O — fetching weather, playlists, or payment status.
Note: The weather sandbox simulates real-world failures: ~1 in 3 requests returns HTTP 503. Run multiple times to see error handling in action.
JAVASCRIPT
async function fetchWeather(city) {
const res = await fetch(
`https://api.openweathermap.org/data/2.5/weather?q=${city}&units=metric&appid=demo`
);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
}Fetch weather — handles API failuresOpenWeatherMap API (sandbox)
Console
// Click Run — watch API traces and console output