24 lines
580 B
TypeScript
24 lines
580 B
TypeScript
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();
|
|
}
|