New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

rehit

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehit

Retry mechanism for Rest APIs

latest
npmnpm
Version
1.2.0
Version published
Weekly downloads
11
22.22%
Maintainers
1
Weekly downloads
 
Created
Source

Rehit

Retry mechanism is now option rich, easy to plugin and supporting all new NodeJS features.

Installation

npm i rehit

Usage

//Packages
const rehit = require('rehit');
const axios = require('axios');

//Simple retry- retry five times with 1 sec interval
const simpleRehit = async () => {
    const [apiError, apiRes] = await rehit(axios.get('http://goog1234525.com'), 5, 1000);
    console.log(apiError, apiRes);  
}

//skip some case
const skipRehit = async () => {
    const [apiError, apiRes] = await rehit(axios.get('http://goog1234525.com'), 5, 1000, {code: 'ENOTFOUND'});
    console.log(apiError, apiRes);
}

//on-failure after retry 
const onFailureRehit = () => {
    rehit(axios.get('http://goog1234525.com'), 5, 1000, {code: 'ENOTFOUND'}, (error) => {
        console.log(error.code);
    })
}

API

rehit(api: Promise, count: Number, time: Number, skip: Object, onFailure: Function) => Array
  • api : The api request should be sent in a promisified manner. For example: axios.get('http://goog1234525.com') .
  • count : This is the number of retries. Just the number is to be passed. Ex. 5 .
  • time : This is the time interval (in ms) between two API request to retry. Ex. 1000 for 1s interval.
  • skip : This is an Object with single key-value pair. The key should be one of the keys of the expected error object. For example, if we pass {code: 'ENOTFOUND'} it will not retry further on getting error having {code: 'ENOTFOUND'}.
  • onFailure : This is a fail over mechanism. One is to define a function what is to be called on the exhaustion of all the retries and api is still returning error.

Author

Saikat Bhattacharya ( @saikatbhattacharya )

Keywords

retry

FAQs

Package last updated on 03 May 2018

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