raycer/frontend/public/js/api.js

23 lines
628 B
JavaScript
Raw Permalink Normal View History

const BASE = '/api';
async function req(path, opts = {}) {
const res = await fetch(`${BASE}${path}`, {
headers: { 'content-type': 'application/json' },
...opts,
});
if (!res.ok) {
const text = await res.text().catch(() => '');
throw new Error(`HTTP ${res.status} ${path}: ${text}`);
}
return res.json();
}
export const api = {
health: () => req('/health'),
listGoals: () => req('/goals'),
listCompletionsSince: (since = 0) =>
req(`/completions?since=${encodeURIComponent(since)}`),
putCompletion: (payload) =>
req('/completions', { method: 'PUT', body: JSON.stringify(payload) }),
};