1.1.0 • Published 10 months ago

@netly/node-fetch v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

node-fetch with native fetch + retry + timeout

Inspired by node-fetch-retry-timeout.

Tiny replacement for native fetch with additional benefits.

Installation

npm i @netly/node-fetch

Parameters

Same as in native fetch, but with small extension. Everything is optional.

parametertypedescriptiondefault
retrynumbernumber of times to retry the request3
timeoutnumbernumber of ms to wait before request cancel20_000
retryStrategyFunctionexponential backoff strategy(times) => Math.min((2 ** times - 1) * 1000, 20000)
retryOnHttpResponseFunctioncan retry based on http response statuses(response) => response.status >= 500;

retry

retry?: number

timeout

timeout?: number

retryStrategy

Calculates how long to wait before next retry. times - the number of retry. To disable retry strategy: () => 0

retryStrategy: (times: number): number => Math.min((2 ** times - 1) * 1000, 20000);

retryOnHttpResponse

Check if response is desired. If no - throw error and send request one more time.

retryOnHttpResponse: (response: globalThis.Response) => response.status >= 500;

Example

For cjs

const { default: fetch } = require('@netly/node-fetch');
// or 
const { fetch } = require('@netly/node-fetch');

const response = await fetch('https://www.google.com');

For esm

import { fetch } from '@netly/node-fetch';
// or
import fetch from '@netly/node-fetch';

const response = await fetch('https://www.google.com');

For ts

import { fetch } from '@netly/node-fetch';
// or 
import fetch from '@netly/node-fetch';

const response = await fetch('https://www.google.com');
1.1.0

10 months ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago