Parallel Fetch
Promise.all + multiple GETs on the real network (Phase 13 pattern).
Independent requests should start together. Use
Promise.all (Phase 13) with several fetch
calls. One HTTP failure (after your ok check) fails the group.
Results appear here.
Important JavaScript
async function getPost(id) {
const response = await fetch(BASE + id);
if (!response.ok) {
throw new Error("HTTP " + response.status);
}
return response.json();
}
const posts = await Promise.all([
getPost(1),
getPost(2),
getPost(3)
]);