express-http-client
Version:
middleware style interceptor; fetch based 0 dependancy imperative light weight http handler.
52 lines • 2.33 kB
TypeScript
/**
* Factory class for creating HttpClient instances with configured interceptors
*
* @class
* @description
* HttpClientFactory provides a fluent interface for configuring and creating
* HttpClient instances with custom request and response interceptors.
* Interceptors can be used to modify requests before they are sent or
* responses before they are returned to the caller.
*/
export default class HttpClientFactory {
requestInterceptors: any[];
responseInterceptors: any[];
/**
* Adds one or more request interceptors to the factory
*
* @param {...Function} interceptors - Functions that will intercept requests
* @returns {HttpClientFactory} The current factory instance for chaining
* @throws {Error} If any interceptor is not a function
*
* @description
* Request interceptors are executed in the order they are added before a request is sent.
* Each interceptor should be a function that accepts and can modify the request.
*/
addRequestInterceptor(...interceptors: Function[]): HttpClientFactory;
/**
* Adds one or more response interceptors to the factory
*
* @param {...Function} interceptors - Functions that will intercept responses
* @returns {HttpClientFactory} The current factory instance for chaining
* @throws {Error} If any interceptor is not a function
*
* @description
* Response interceptors are executed in the order they are added after a response
* is received but before it is returned to the caller. Each interceptor should be
* a function that accepts and can modify the response.
*/
addResponseInterceptor(...interceptors: Function[]): HttpClientFactory;
/**
* Creates a new HttpClient instance with the configured interceptors
*
* @param {string} [baseUrl=''] - The base URL to use for all requests made by this client
* @returns {HttpClient} A new HttpClient instance configured with the specified interceptors
*
* @description
* Creates and returns a new HttpClient instance with the base URL and all
* request and response interceptors that have been added to this factory.
*/
create(baseUrl?: string): HttpClient;
}
import HttpClient from './HttpClient';
//# sourceMappingURL=HttpClientFactory.d.ts.map