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.
 
 

15 lines
452 B

  1. export type DJAPIEndpoint = "/rp-articles";
  2. export interface DJAPIResultMap extends Record<DJAPIEndpoint, unknown> {
  3. "/rp-articles": { slug: string; name: string }[];
  4. }
  5. export type DJAPIResult = DJAPIResultMap[DJAPIEndpoint];
  6. export default async function getDJAPI<T extends DJAPIEndpoint>(
  7. hostUrl: string,
  8. endpoint: T,
  9. ): Promise<DJAPIResultMap[typeof endpoint]> {
  10. return await (await fetch(`${hostUrl}/api${endpoint}`)).json();
  11. }