claude/skills/web-project-scaffold-containerized-python/templates/project/app/static/js/api.js
Neil Bantoc 5201aa9bd5 Add web-frontend, web-project-audit and web-project-scaffold-containerized-python skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 16:26:33 -08:00

14 lines
633 B
JavaScript

// Small fetch wrapper: JSON in, JSON out, errors carry the server's message.
export async function getJSON(path, options = {}) {
const response = await fetch(path, { headers: { Accept: "application/json" }, ...options });
if (!response.ok) {
let detail = response.statusText;
try { detail = (await response.json()).detail ?? detail; } catch {}
throw new Error(`${response.status} ${detail}`);
}
return response.json();
}
export function postJSON(path, body) {
return getJSON(path, { method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json" }, body: JSON.stringify(body) });
}