No description
  • TypeScript 100%
Find a file
2025-11-09 13:56:53 +01:00
.gitignore Added README, updated dependencies, and improved URL handling 2025-11-09 13:56:53 +01:00
index.ts Added README, updated dependencies, and improved URL handling 2025-11-09 13:56:53 +01:00
package.json Added README, updated dependencies, and improved URL handling 2025-11-09 13:56:53 +01:00
README.md Added README, updated dependencies, and improved URL handling 2025-11-09 13:56:53 +01:00
tsconfig.json Initial commit 2022-01-02 17:02:16 +01:00
types.ts Fixed types 2022-06-11 16:56:20 +02:00

@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/fetch

Usage

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 URL
  • retry, retryInterval, retryIntervalMin, retryIntervalMax retry settings
  • requestInterval, requestIntervalMin, requestIntervalMax intervals between requests
  • chunkSize batch size for chunkedPromise
  • http additional Axios config (headers, etc.)

Scripts

  • yarn build TypeScript compilation
  • yarn clean Remove dist folder
  • yarn test Run tests (not implemented yet)

License

ISC

Repository

GitLab - media-info/fetch