Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
async function apiFetch(path, { method = "GET", body, signal } = {}) { const res = await fetch(`/api${path}`, { method, signal, headers: { "Content-Type": "application/json", "Authorization": `Bearer ${getToken()}` }, body: body ? JSON.stringify(body) : undefined, }); if (!res.ok) throw new Error(`HTTP ${res.status}`); return res.json(); }
Result
Open