UNPKG

express-http-client

Version:

middleware style interceptor; fetch based 0 dependancy imperative light weight http handler.

41 lines 1.76 kB
/** * HTTP client with request/response interceptor support * * @class * @description * A fetch-based HTTP client that supports middleware-style interceptors * for both requests and responses. Allows setting a base URL that will * be prepended to all request URLs. */ export default class HttpClient { /** * Creates a new HTTP client * * @constructor * @param {string} [baseUrl=''] - Base URL to prepend to all requests * @param {Function[]} [requestInterceptors=[]] - Array of request interceptor functions * @param {Function[]} [responseInterceptors=[]] - Array of response interceptor functions */ constructor(baseUrl?: string, requestInterceptors?: Function[], responseInterceptors?: Function[]); /** * Sends an HTTP request with the given URL and options. * * @async * @param {string} url - The URL path to send the request to (will be appended to baseUrl) * @param {RequestInit} [options] - Fetch API options for the request * @returns {Promise<Response>} The response after being processed by any response interceptors * * @description * This method: * 1. Creates a Request object combining baseUrl and the provided url * 2. Initializes a shared Map store for data persistence between interceptors * 3. Processes the request through any request interceptors * 4. If request processing fails, returns a 424 (Failed Dependency) response * 5. Executes the fetch operation with the processed request * 6. Processes the response through any response interceptors * 7. Returns the final response */ send(url: string, options?: RequestInit): Promise<Response>; #private; } //# sourceMappingURL=HttpClient.d.ts.map