/** * @module Agent Interface * * @description Describes the interface which must be defined for an Agent to work with core-interface */ /** * Agent * * This module specifies the interface for the HTTP agent required by the bare * client library */ /** * Agent * * The sole requirement of this class is to implement a JSON request method * that supports HTTP attributes defined in `HttpRequest` * * The underlying implementation (i.e. whether it uses node's `http` module, * or browser XHR) is the responsibility of downstream client implementations. * Namely @ideal-postcodes/core-browser and @ideal-postcodes/core-node * * @example * * ```javascript * class AxiosAgent implements Agent { * public http(options) { * return axios.request(options); * } * } * ``` */ export interface Agent { http: Http; } /** * Request * * Dispatches HTTP JSON http request */ export interface Http { (httpRequest: HttpRequest): Promise; } export declare type HttpVerb = "GET" | "POST" | "DELETE" | "PUT" | "PATCH" | "DELETE"; /** * Describes HTTP request */ export interface HttpRequest { method: HttpVerb; body?: any; timeout: number; url: string; header: Header; query: Query; } export declare type StringMap = Record; /** * Header */ export declare type Header = StringMap; export declare type Query = StringMap; /** * Metadata * * Stores any meta data that an agent may decide to decorate the response with * * E.g. for a browser client, the agent could add an XMLHttpRequest object */ interface Metadata { [key: string]: unknown; } /** * HttpResponse * * Represents HTTP Response of request */ export interface HttpResponse { httpStatus: number; header: Header; body: any; httpRequest: HttpRequest; metadata?: Metadata; } export {};