import { Response, QueryParams, HTTPHeaders, ServerConfig } from "./interfaces"; import { Json } from "../interfaces"; /** * A low level abstraction for communicating with an API server. * * In most cases direct use of this class will not be needed. It is recommended * to extend the * */ export declare class APIServer { /** * The hostname and protocol of the server. */ _baseurl: string; /** * The request timeout in milliseconds. */ timeout: number; /** * Number of times to retry timed out requests. */ retries: number; /** * Headers to be applied to every request. */ headers: HTTPHeaders; /** * Promise for the JWT token */ readonly tokenPromise: Promise; constructor({ baseurl, timeout, retries, headers }?: ServerConfig); /** * The base url for the server. * * @note The baseurl is normalised to remove any trailing '/' */ get baseurl(): string; set baseurl(baseurl: string); /** * Make a post request to the API server. * * @param path The path to the endpoint on the API server. * @param queryParams Any query parameters that should be added. * @param payload The data to send with the request. * * @returns The response from the server. */ post(path: string, queryParams?: QueryParams, payload?: Json): Promise; /** * Make a put request to the API server. * * @param path The path to the endpoint on the API server. * @param resourceId The resource id of the resource we want to fetch. * @param queryParams Any query parameters that should be added. * @param payload The data to send with the request. * * @returns The response from the server. */ put(path: string, resourceId: string, queryParams?: QueryParams, payload?: Json): Promise; /** * Make a get request to the API server. * * @param path The path to the endpoint on the API server. * @param resourceId The resource id of the resource we want to fetch. * @param queryParams Any query parameters that should be added. * * @returns The response from the server. */ get(path: string, resourceId?: string, queryParams?: QueryParams): Promise; /** * Make a delete request to the API server. * * @param path The path to the endpoint on the API server. * @param resourceId The resource id of the resource we want to fetch. * * @returns The response from the server. */ delete(path: string, resourceId: string): Promise; /** * Send the request to the server. * * @param method The http method * @param path The path to the resource. * @param queryParams The query parameters to include with the request. * @param payload The data to send with the request. * @param headers The headers to attach to the request. * * @returns The server response. */ private sendRequest; /** * Make the configuration object for the `Request`. * * @param queryParams The query parameters to include with the request. * @param payload The data to send with the request. * @param headers The headers to attach to the request. * * @returns The config to use when making the request. */ private makeRequestConfig; /** * Make sure path has starting and trailing '/'. * * @param path The path to the resource. * * @returns The normalised path. */ private normalisePath; }