Files
jellomator/frontend/src/lib/api.ts

23 lines
720 B
TypeScript

export type SetupState = { needs_setup: boolean; current_user: { username: string } | null };
export type LinkItem = {
id: number;
name: string;
url: string;
description: string;
category: string;
sort_order?: number;
enabled: boolean;
icon_url: string | null;
};
async function request<T>(path: string, init?: RequestInit): Promise<T> {
const res = await fetch(path, {
credentials: 'include',
headers: init?.body instanceof FormData ? undefined : { 'Content-Type': 'application/json', ...(init?.headers || {}) },
...init,
});
if (!res.ok) throw new Error(await res.text());
return res.status === 204 ? (undefined as T) : ((await res.json()) as T);
}
export const api = { request };