Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

phin-retry

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phin-retry

The ultra-lightweight Node.js HTTP client

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

phin-retry

Build Coverage

The ultra-lightweight Node.js HTTP client.

This is a wrapper around Phin that adds support for retry & looks like request-promise.

Install

npm install phin-retry

Usage

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 behaviour with custom retry strategy function.
  • Responses with status codes < 200 & >= 300 are thrown as errors. Override this behaviour with custom error strategy function.
  • All options from phin are supported. Refer Phin for more usage examples.

API

Defaults

Access default options through request.defaults.

OptionTypeDescription
retrynumbermax no of times to retry (1)
delaynumberdelay between retries (100ms)
networkErrorDelayanydelay for network errors (1000ms)
retryStrategyfunctiondefault retry strategy function
delayStrategyfunctiondefault delay strategy function
errorStrategyfunctiondefault error strategy function

Options

It supports all options from phin, refer Phin more details.

MethodTypeDescription
urlstringrequest url
qsobjectquery parameters
authobjectauthentication object
headersobjectheaders object
retrynumbermax no of times to retry
delaynumberdelay between retries
bodyanyequivalent to data in phin
fullResponsebooleanreturns full phin response
retryStrategyfunctioncustom retry strategy function
delayStrategyfunctioncustom delay strategy function
errorStrategyfunctioncustom error strategy function

Keywords

FAQs

Package last updated on 01 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc