This commit is contained in:
Daniel Ledda
2024-11-01 15:42:09 +01:00
parent f60e975765
commit 7539e6ed48
50 changed files with 2004 additions and 750 deletions

14
app/api.ts Normal file
View File

@@ -0,0 +1,14 @@
export type DJAPIEndpoint = "/rp-articles";
export interface DJAPIResultMap extends Record<DJAPIEndpoint, unknown> {
"/rp-articles": { slug: string; name: string }[];
}
export type DJAPIResult = DJAPIResultMap[DJAPIEndpoint];
export default async function getDJAPI<T extends DJAPIEndpoint>(
hostUrl: string,
endpoint: T,
): Promise<DJAPIResultMap[typeof endpoint]> {
return await (await fetch(`${hostUrl}/api${endpoint}`)).json();
}