feat(web): add api.{get,post,del} typed facade over apiFetch
This commit is contained in:
@@ -33,3 +33,11 @@ export async function apiFetch(path: string, init?: RequestInit): Promise<unknow
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
export const api = {
|
||||
get: <T>(path: string): Promise<T> => apiFetch(path) as Promise<T>,
|
||||
post: <T>(path: string, body: unknown): Promise<T> =>
|
||||
apiFetch(path, { method: 'POST', body: JSON.stringify(body) }) as Promise<T>,
|
||||
del: (path: string): Promise<null> =>
|
||||
apiFetch(path, { method: 'DELETE' }) as Promise<null>
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user