UNPKG

@push.rocks/webrequest

Version:

Modern, fetch-compatible web request library with intelligent HTTP caching, retry strategies, and fault tolerance.

69 lines (68 loc) 2.21 kB
/** * WebrequestClient - Advanced configuration and global interceptors */ import type { IWebrequestOptions } from './webrequest.types.js'; import type { TRequestInterceptor, TResponseInterceptor, TErrorInterceptor } from './interceptors/interceptor.types.js'; export declare class WebrequestClient { private interceptorManager; private cacheManager; private deduplicator; private defaultOptions; constructor(options?: Partial<IWebrequestOptions>); /** * Add a global request interceptor */ addRequestInterceptor(interceptor: TRequestInterceptor): void; /** * Add a global response interceptor */ addResponseInterceptor(interceptor: TResponseInterceptor): void; /** * Add a global error interceptor */ addErrorInterceptor(interceptor: TErrorInterceptor): void; /** * Remove a request interceptor */ removeRequestInterceptor(interceptor: TRequestInterceptor): void; /** * Remove a response interceptor */ removeResponseInterceptor(interceptor: TResponseInterceptor): void; /** * Remove an error interceptor */ removeErrorInterceptor(interceptor: TErrorInterceptor): void; /** * Clear all interceptors */ clearInterceptors(): void; /** * Clear the cache */ clearCache(): Promise<void>; /** * Execute a request with all configured features */ request(url: string | Request, options?: IWebrequestOptions): Promise<Response>; /** * Internal request execution with caching and retry */ private executeRequest; /** * Convenience method: GET request returning JSON */ getJson<T = any>(url: string, options?: IWebrequestOptions): Promise<T>; /** * Convenience method: POST request with JSON body */ postJson<T = any>(url: string, data: any, options?: IWebrequestOptions): Promise<T>; /** * Convenience method: PUT request with JSON body */ putJson<T = any>(url: string, data: any, options?: IWebrequestOptions): Promise<T>; /** * Convenience method: DELETE request */ deleteJson<T = any>(url: string, options?: IWebrequestOptions): Promise<T>; }