UNPKG

@jsynple/core

Version:

All the core modules and types for the Synple application

28 lines (27 loc) 1.39 kB
export interface Requestable { get(url: string, payload: Record<string, unknown>): Promise<Response>; post(url: string, payload: Record<string, unknown>): Promise<Response>; put(url: string, payload: Record<string, unknown>): Promise<Response>; delete(url: string, payload: Record<string, unknown>): Promise<Response>; } export type Fetcher = typeof fetch; /** * The API is capable of querying a proxy route in the frontend to directly query the API in the backend. * It automatically puts the prefix to query the proxy route on the frontend so that it does not have to * be done in each and every call. It does NOT however handle unknownthing regarding authentication tokens. * @author Vincent Courtois <courtois.vincent@outlook.com> */ export declare class Api implements Requestable { private fetcher; private prefix; constructor(fetcher: Fetcher, prefix?: string); get(url?: string, params?: Record<string, unknown>): Promise<Response>; post(url?: string, data?: Record<string, unknown>): Promise<Response>; put(url?: string, data?: Record<string, unknown>): Promise<Response>; delete(url?: string, params?: Record<string, unknown>): Promise<Response>; private makeRequest; complete(url: string): string; completeWithParams(url: string, params: Record<string, string>): string; private timestamp; private body; }