A resilient NestJS module to handle HTTP requests with configurable retry strategies.
- Description
- Features
- Installation
- Configuration
- Usage
- Examples
- Contribute & Disclaimer
- License
- Contributors
This module integrates an HTTP retry functionality into the NestJS framework, providing configurable retry strategies like Exponential Backoff or Constant Interval retries.
The NestJS HTTP Retry module supports these key features:
- Easy-to-use configurable retry strategies
- Exponential Backoff retries
- Constant Interval retries
- No-retry option
You can install the module using yarn or npm:
$ yarn add @bamada/nestjs-http-retry
OR
$ npm i @bamada/nestjs-http-retry
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,
}),
],
// Other module properties
})
export class AppModule {}
Once configured, use the HttpRetryStrategiesService
to make HTTP requests with the built-in retry strategies.
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();
}
}
Feel free to contribute by submitting pull requests or opening issues. This module comes with no warranty; use it at your own risk.
Distributed under the MIT License. See LICENSE
for more information.
madcam |
This project follows the all-contributors specification. Contributions of any kind welcome!