29 lines
638 B
TypeScript
29 lines
638 B
TypeScript
type Method = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
|
|
export interface FrontendApiEndpoint<M extends Method, P extends string, T, R> {
|
|
method: M;
|
|
path: P;
|
|
request?: T;
|
|
response?: R;
|
|
}
|
|
|
|
function endpointDef<T, R>(
|
|
method: Method,
|
|
path: string
|
|
): FrontendApiEndpoint<Method, string, T, R> {
|
|
return {
|
|
method,
|
|
path,
|
|
};
|
|
}
|
|
|
|
export const feEndpoints = {
|
|
defaultSounds: endpointDef<{}, string[]>("GET", "default-sounds"),
|
|
} as const;
|
|
|
|
type Endpoints = typeof feEndpoints;
|
|
|
|
export type FrontendApiEndpoints = {
|
|
[N in keyof Endpoints as Endpoints[N]["path"] & string]: Endpoints[N];
|
|
};
|