@push.rocks/webrequest
Version:
Modern, fetch-compatible web request library with intelligent HTTP caching, retry strategies, and fault tolerance.
55 lines (54 loc) • 2.05 kB
TypeScript
/**
* Main webrequest function - fetch-compatible API
*/
import type { IWebrequestOptions } from './webrequest.types.js';
import { WebrequestClient } from './webrequest.client.js';
/**
* Fetch-compatible webrequest function
* Drop-in replacement for fetch() with caching, retry, and fault tolerance
*
* @param input - URL or Request object
* @param init - Request options (standard RequestInit + webrequest extensions)
* @returns Promise<Response>
*
* @example
* ```typescript
* // Simple GET request
* const response = await webrequest('https://api.example.com/data');
* const data = await response.json();
*
* // With caching
* const response = await webrequest('https://api.example.com/data', {
* cacheStrategy: 'cache-first',
* cacheMaxAge: 60000
* });
*
* // With retry
* const response = await webrequest('https://api.example.com/data', {
* retry: {
* maxAttempts: 3,
* backoff: 'exponential'
* }
* });
*
* // With fallback URLs
* const response = await webrequest('https://api.example.com/data', {
* fallbackUrls: ['https://backup.example.com/data'],
* retry: true
* });
* ```
*/
export declare function webrequest(input: string | Request | URL, init?: IWebrequestOptions): Promise<Response>;
export declare namespace webrequest {
var getJson: <T = any>(url: string, options?: IWebrequestOptions) => Promise<T>;
var postJson: <T = any>(url: string, data: any, options?: IWebrequestOptions) => Promise<T>;
var putJson: <T = any>(url: string, data: any, options?: IWebrequestOptions) => Promise<T>;
var deleteJson: <T = any>(url: string, options?: IWebrequestOptions) => Promise<T>;
var addRequestInterceptor: (interceptor: any) => void;
var addResponseInterceptor: (interceptor: any) => void;
var addErrorInterceptor: (interceptor: any) => void;
var clearInterceptors: () => void;
var clearCache: () => Promise<void>;
var createClient: (options?: Partial<IWebrequestOptions>) => WebrequestClient;
var getDefaultClient: () => WebrequestClient;
}