Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
async function apiFetch(url, opts = {}) { const res = await fetch(url, opts); if (!res.ok) { const body = await res.text().catch(() => ""); throw Object.assign(new Error(`HTTP ${res.status}`), { status: res.status, body }); } return res.json(); }
Result
Open