A resilient NestJS module to handle HTTP requests with configurable retry strategies.
Table of Contents
Description
This module integrates an HTTP retry functionality into the NestJS framework, providing configurable retry strategies like Exponential Backoff or Constant Interval retries.
Features
The NestJS HTTP Retry module supports these key features:
- Easy-to-use configurable retry strategies
- Exponential Backoff retries
- Constant Interval retries
- No-retry option
Installation
You can install the module using yarn or npm:
$ yarn add @bamada/nestjs-http-retry
OR
$ npm i @bamada/nestjs-http-retry
Configuration
To configure the retry strategies, pass the desired settings when registering the module:
import {
HttpRetryStrategiesModule,
RetryStrategyType,
} from '@bamada/nestjs-http-retry';
@Module({
imports: [
HttpRetryStrategiesModule.register({
type: RetryStrategyType.Interval,
maxAttempts: 3,
intervalMs: 1000,
}),
],
})
export class AppModule {}
Usage
Once configured, use the HttpRetryStrategiesService
to make HTTP requests with the built-in retry strategies.
Examples
Below is a simple example of how to use the HTTP Retry Strategies service:
import { Injectable } from '@nestjs/common';
import { HttpRetryStrategiesService } from '@bamada/nestjs-http-retry';
@Injectable()
export class YourService {
constructor(private readonly httpRetryService: HttpRetryStrategiesService) {}
async getResource() {
return this.httpRetryService.get('https://your.api/resource').toPromise();
}
}
Contribute & Disclaimer
Feel free to contribute by submitting pull requests or opening issues. This module comes with no warranty; use it at your own risk.
License
Distributed under the MIT License. See LICENSE
for more information.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind welcome!