|
1234567891011121314151617181920212223 |
- export type DJAPIEndpoint = "/rp-articles";
-
- type RPArticle = {
- title: string,
- slug: string;
- titleDe: string,
- titleEn: string,
- author: string,
- tags?: string[],
- };
-
- export interface DJAPIResultMap extends Record<DJAPIEndpoint, unknown> {
- "/rp-articles": RPArticle[];
- }
-
- 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();
- }
|