import { Decoder } from '@veupathdb/wdk-client/lib/Utils/Json'; /** * Represents an HTTP-like request for a resource. */ export interface ApiRequest { /** Path to resource, relative to a fixed base url. */ path: string; /** Request method for resource. */ method: string; /** Body of request */ body?: any; /** Headers to add to the request. */ headers?: Record; /** Transform response body. This is a good place to do validation. */ transformResponse: (body: unknown) => Promise; } export interface ApiRequestCreator { (...args: U): ApiRequest; } export interface ApiRequestsObject { [Key: string]: ApiRequestCreator; } export declare type BoundApiRequestsObject = { [P in keyof T]: T[P] extends ApiRequestCreator ? (...args: B) => Promise : never; }; export declare function bindApiRequestCreators(requestCreators: T, handler: ApiRequestHandler): BoundApiRequestsObject; /** Helper to create a request with a JSON body. */ export declare function createJsonRequest(init: ApiRequest): ApiRequest; /** Helper to create a request with a plain text body. */ export declare function createPlainTextRequest(init: ApiRequest): ApiRequest; /** Standard transformer that uses a `Json.ts` `decoder` type. */ export declare function standardTransformer(decoder: Decoder): (body: unknown) => Promise; /** * A function that takes an `ApiRequest` and returns a `Promise`. */ export interface ApiRequestHandler { (request: ApiRequest): Promise; } /** * Options for a `fetch`-based request handler. */ export interface FetchApiOptions { /** Base url for service endpoint. */ baseUrl: string; /** Global optoins for all requests. */ init?: RequestInit; /** Implementation of `fetch` function. Defaults to `window.fetch`. */ fetchApi?: Window['fetch']; } /** * A `fetch`-based implentation of an `ApiRequestHandler`. */ export declare function createFetchApiRequestHandler(options: FetchApiOptions): ApiRequestHandler; export declare abstract class FetchClient { protected readonly baseUrl: string; protected readonly init: RequestInit; protected readonly fetchApi: Window['fetch']; constructor(options: FetchApiOptions); protected fetch(apiRequest: ApiRequest): Promise; } //# sourceMappingURL=api.d.ts.map