1.0.11 • Published 3 years ago

retryable-request v1.0.11

Weekly downloads
23
License
MIT
Repository
-
Last release
3 years ago

retryable-request

Sending retryable requests easily

Table of Contents

- [Features](#features)
- [Installing](#installing)
- [Example](#example)
- [Credits](#credits)
- [License](#license)

Features

- Send normal request using sendRequest function
- Creating retryable request using createRetryableRequest function
- Send retryable request using sendRetryable request function
- Alternatively you can perform the previous functionality using RetryableRequest class instead.
- Everything is promise based and compaitable with axios http client

Installing

Using npm:

$ npm install retryable-request

Using yarn:

$ yarn add retryable-request

Example

const { createRetryableRequest } = require("retryable-request");

const request = createRetryableRequest({
  requestOptions: {
    url: "https://jsonplaceholder.typicode.com/todos",
  },
  retryOptions: {
    retries: 3,
  },
  retryCB: (e, currentAttempt) =>
    console.log(`${e.message} - currentAttempt: ${currentAttempt}`),
});

request()
  .then((data) => console.log(data.data))
  .catch((e) => console.log(e.message));
// using RetryableRequest class which supports axios interceptors and have default ones
  
  const {RetryableRequest}  =  require("retryable-request");
  const client = RetryableRequest.instance({ defaultInterceptors: true });
  // normal request
  client.sendRequest({
      url:"https://jsonplaceholder.typicode.com/todos",
  }).then(console.log).catch(console.log);

  // retryable request
  client.sendRetryableRequest({
      requestOptions: {
        url: "https://jsonplaceholder.typicode.com/todos",
      },
      retryOptions: {
        retries: 3,
      },
      retryCB: (e, currentAttempt) =>
        console.log(e,currentAttempt),
  }).then(console.log).catch(console.log);

Credits

- Abd Allah Zidan

License

- MIT
1.0.11

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.10

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago