UNPKG

@dvsa/appdev-api-common

Version:

Utils library for common API functionality

49 lines (48 loc) 1.83 kB
type HTTPResponse = { url: string; status: number; statusText: string; headers: Record<string, string>; redirected: boolean; type: "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect"; body?: unknown; }; export declare class HTTPError extends Error { response: HTTPResponse; constructor(message: string, response: HTTPResponse); } export declare class HTTP { /** * Performs an HTTP GET request. * Note: This method will throw an HTTPError if the response is not ok (status code 200-299) to emulate Axios behaviour. * @param url * @param options */ static get(url: string, options?: Omit<RequestInit, "method" | "body">): Promise<HTTPResponse>; /** * Performs an HTTP POST request. * Note: This method will throw an HTTPError if the response is not ok (status code 200-299) to emulate Axios behaviour. * @param url * @param body * @param options */ static post<T>(url: string, body: T, options?: Omit<RequestInit, "method" | "body">): Promise<HTTPResponse>; /** * Performs an HTTP PUT request. * Note: This method will throw an HTTPError if the response is not ok (status code 200-299) to emulate Axios behaviour. * @param url * @param body * @param options */ static put<T>(url: string, body: T, options?: Omit<RequestInit, "method" | "body">): Promise<HTTPResponse>; /** * Performs an HTTP DELETE request. * Note: This method will throw an HTTPError if the response is not ok (status code 200-299) to emulate Axios behaviour. * @param url * @param options */ static delete(url: string, options?: Omit<RequestInit, "method" | "body">): Promise<HTTPResponse>; private static serialise; private static prepareBody; } export {};