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