djledda.de main
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api.ts 580 B

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
1234567891011121314151617181920212223
  1. export type DJAPIEndpoint = "/rp-articles";
  2. type RPArticle = {
  3. title: string,
  4. slug: string;
  5. titleDe: string,
  6. titleEn: string,
  7. author: string,
  8. tags?: string[],
  9. };
  10. export interface DJAPIResultMap extends Record<DJAPIEndpoint, unknown> {
  11. "/rp-articles": RPArticle[];
  12. }
  13. export type DJAPIResult = DJAPIResultMap[DJAPIEndpoint];
  14. export default async function getDJAPI<T extends DJAPIEndpoint>(
  15. hostUrl: string,
  16. endpoint: T,
  17. ): Promise<DJAPIResultMap[typeof endpoint]> {
  18. return await (await fetch(`${hostUrl}/api${endpoint}`)).json();
  19. }