updatge
This commit is contained in:
14
app/api.ts
Normal file
14
app/api.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export type DJAPIEndpoint = "/rp-articles";
|
||||
|
||||
export interface DJAPIResultMap extends Record<DJAPIEndpoint, unknown> {
|
||||
"/rp-articles": { slug: string; name: string }[];
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
Reference in New Issue
Block a user