@media-info/fetch
v1.1.5
Published
TypeScript library for robust HTTP GET requests with support for retries, intervals, proxy, timeouts, and batch (chunked) processing. Built on top of [axios](https://github.com/axios/axios).
Readme
@media-info/fetch
TypeScript library for robust HTTP GET requests with support for retries, intervals, proxy, timeouts, and batch (chunked) processing. Built on top of axios.
Features
- Request retries with configurable interval
- Proxy or base URL support
- Intervals between requests (static or random)
- Timeout for individual requests
- Batch processing of arrays of async operations (chunkedPromise)
- Fully typed with TypeScript
Installation
npm install @media-info/fetchUsage
import { Fetch, Config } from '@media-info/fetch';
const config: Config = {
baseUrl: 'https://api.example.com',
retry: 3,
retryInterval: 1000,
requestInterval: 500,
chunkSize: 10,
http: {
headers: { 'Authorization': 'Bearer ...' }
}
};
const fetcher = new Fetch(config);
// Simple GET request with retry
fetcher.req('/data').then(response => {
console.log(response.data);
});
// Batch processing of an array
const ids = [1,2,3,4,5];
fetcher.chunkedPromise(ids, id => fetcher.req(`/item/${id}`)).then(results => {
console.log(results);
});API
Class Fetch
- constructor(config: Config) – Initialize with configuration
- req(url: string, opt?: AxiosRequestConfig) – GET request with retry and intervals
- chunkedPromise<T, K>(items: T[], cb: (i: T) => Promise) – Batch processing of async operations with timeout
Configuration (Config)
baseUrl/proxyUrl– base/proxy URLretry,retryInterval,retryIntervalMin,retryIntervalMax– retry settingsrequestInterval,requestIntervalMin,requestIntervalMax– intervals between requestschunkSize– batch size for chunkedPromisehttp– additional Axios config (headers, etc.)
Scripts
yarn build– TypeScript compilationyarn clean– Remove dist folderyarn test– Run tests (not implemented yet)
License
ISC
