# phin-retry

> The ultra-lightweight Node.js HTTP client

Latest version **2.0.0** (published 2025-12-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install phin-retry
pnpm add phin-retry
yarn add phin-retry
bun add phin-retry
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2025-12-21 |
| First published | 2020-04-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 1 |
| Unpacked size | 12.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Anudeep |
| Maintainers | asaianudeep |
| Keywords | phin, http, https, request, request-promise, ajax, url, uri, fetch, retry, delay |

## Links

- npm: https://www.npmjs.com/package/phin-retry
- Repository: https://github.com/ASaiAnudeep/phin-retry
- Homepage: https://github.com/ASaiAnudeep/phin-retry#readme
- Issues: https://github.com/ASaiAnudeep/phin-retry/issues
- npm.io page: https://npm.io/package/phin-retry

## Dependencies (1)

- [phinx](https://npm.io/package/phinx.md) 1.1.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2025-12-21
- 1.0.3 — 2020-08-06
- 1.0.2 — 2020-08-02
- 1.0.1 — 2020-08-01
- 1.0.0 — 2020-04-29

## README

# phin-retry

![Build](https://github.com/ASaiAnudeep/phin-retry/workflows/Build/badge.svg?branch=master)
![Coverage](https://img.shields.io/codeclimate/coverage/ASaiAnudeep/phin-retry)

The ultra-lightweight Node.js HTTP client.

> This is a wrapper around [Phin](https://github.com/ethanent/phin) that adds support for retry & looks like [request-promise](https://github.com/request/request-promise).

## Install

```shell
npm install phin-retry
```

## Usage

```javascript
const request = require('phin-retry');

// should be used in async context
const response = await request.get('https://jsonplaceholder.typicode.com/posts/1');

await request.post({
    url: 'http://localhost:9393/api/post',
    body: { msg: 'input' },
    retry: 3,
    delay: 500
  });

// custom retry, error & delay strategy
const response = await request.delete({
    url: 'http://localhost:9393/api/delete',
    auth: {
      user: 'name',
      pass: 'secret'
    },
    errorStrategy: ({response, error, options}) => {
        if (error) return true;
        if (response.statusCode >= 400) {
          return false;
        }
        return true;
      },
    retryStrategy: ({response, error, options}) => {
        if (error) return true;
        if (options.method === 'POST') return false;
        if (response.statusCode >=200 && response.StatusCode < 300) {
          return false;
        }
        return true;
      },
    delayStrategy: ({response, error, options, delay}) => {
        if (error) return 5000;
        return 2000;
      },
  });

```

* It supports **get**, **post**, **put**, **delete**, **patch** HTTP methods.
* By default, this library will retry once on failure (StatusCode >= 500 & network errors) with a delay of 100 or 1000 milliseconds. Override this behavior with custom retry strategy function.
* Responses with status codes < 200 & >= 300 are thrown as errors. Override this behavior with custom error strategy function.
* All options from **phin** are supported. Refer [Phin](https://www.npmjs.com/package/phin) for more usage examples.
* Access underlying **phin** library through `request.phin`.

## API

### Defaults

Access default options through `request.defaults`.

| Option              | Type     | Description                        |
| ----------------    | -------- | ---------------------------------- |
| `retry`             | number   | max no of times to retry (1)       |
| `delay`             | number   | delay between retries (100ms)      |
| `networkErrorDelay` | number   | delay for network errors (1000ms)  |
| `retryStrategy`     | function | default retry strategy function    |
| `delayStrategy`     | function | default delay strategy function    |
| `errorStrategy`     | function | default error strategy function    |     


### Options

It supports all options from **phin**, refer [Phin](https://www.npmjs.com/package/phin) for more details.

| Method           | Type     | Description                     |
| ---------------- | -------- | ------------------------------- |
| `url`            | string   | request url                     |
| `qs`             | object   | query parameters                |
| `auth`           | object   | authentication object           |
| `headers`        | object   | headers object                  |
| `retry`          | number   | max no of times to retry        |
| `delay`          | number   | delay between retries           |
| `body`           | any      | equivalent to data in phin      |
| `fullResponse`   | boolean  | returns full phin response      |
| `retryStrategy`  | function | custom retry strategy function  |
| `delayStrategy`  | function | custom delay strategy function  |
| `errorStrategy`  | function | custom error strategy function  |

---
_Source: https://npm.io/package/phin-retry · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
