UNPKG

@alwatr/fetch

Version:

Enhanced fetch API with cache strategy, retry pattern, timeout, helper methods and enhanced types.

53 lines 1.52 kB
import { cacheSupported } from './core.js'; import type { FetchOptions, ResponseError } from './type.js'; export { cacheSupported }; export type * from './type.js'; /** * It's a wrapper around the browser's `fetch` function that adds retry pattern, timeout, cacheStrategy, * remove duplicates, etc. * * @see {@link FetchOptions} * @see {@link ResponseSuccess} * @see {@link ResponseError} * * @param options Fetch options. * * @returns A success or error response. * * @example * ```typescript * const responseJson = await fetchJson({ * url: '/api/products', * queryParameters: {limit: 10}, * timeout: 8_000, * retry: 3, * cacheStrategy: 'stale_while_revalidate', * cacheDuplicate: 'auto', * }); * ``` */ export declare function fetchJson<T extends JsonObject>(options: FetchOptions): Promise<T | ResponseError>; /** * It's a wrapper around the browser's `fetch` function that adds retry pattern, timeout, cacheStrategy, * remove duplicates, etc. * * @see {@link FetchOptions} * * @param options Fetch options. * * @returns A promise that resolves to the Response to that request, whether it is successful or not. * * @example * ```typescript * const response = await fetch({ * url: '/api/products', * queryParameters: {limit: 10}, * timeout: 8_000, * retry: 3, * cacheStrategy: 'stale_while_revalidate', * cacheDuplicate: 'auto', * }); * ``` */ export declare function fetch(options: FetchOptions): Promise<Response>; //# sourceMappingURL=main.d.ts.map