Resilience Client
This is an augmented Angular HttpClient which overrides the get method to enrich resilience
behaviour.
Preconditions
Install it via yarn add resilient-http-client
Docs
Default configuration
The default config is the following:
export const DEFAULT_RESILIENCE_CONFIG: Partial<IResilienceConfig> = {
isDelayedAfterMs: 3000,
disableRetry: false,
logResult: false,
trace: false,
waitForUserDecision: false,
retryOnStatusCodeList: [
HttpStatusCode.RequestTimeout,
HttpStatusCode.Locked,
HttpStatusCode.TooManyRequests,
HttpStatusCode.InternalServerError,
HttpStatusCode.BadGateway,
HttpStatusCode.ServiceUnavailable,
HttpStatusCode.GatewayTimeout,
],
retryIntervalInMillisList: [0, 200, 500, 1000, 1000],
topicToConfigDict: {},
onWaitingForUserDecision: (
topic: string,
uuid: string,
retryCount: number,
failedOnStatusCode: HttpStatusCode,
userRetryOrCancel: Subject<boolean>,
): void => {},
onFail: (topic: string, uuid: string, message: string): void => {},
onRequestDelayed: (topic: string, uuid: string): void => {},
onRequestRetry: (
topic: string,
uuid: string,
retryCount: number,
nextRetry: number,
failedOnHttpStatusCode: HttpStatusCode,
): void => {},
onRequestStart: (topic: string, uuid: string): void => {},
onRequestFinalize: (topic: string, uuid: string): void => {},
};
Recommended: use a builder for topic specific resilience config enrichment
export const buildResilienceConfigForTopic = (topic: RESILIENT_API_TOPIC): IResilienceConfig => {
return {
...DEFAULT_RESILIENCE_CONFIG,
...RESILIENCE_CONFIG,
topic,
} as IResilienceConfig;
};
Demo usage:
@Injectable({
providedIn: 'root',
})
export class SampleApiService {
constructor(
private readonly resilientHttpClientService: ResilientHttpClientService,
) {
}
public getYourDtoList$(bySomeId: ISampleId): Observable<ISampleDto[]> {
return this.resilientHttpClientService
.get<
ISampleDto[]
>('/some/url/to/the/dto/api', buildResilienceConfigForTopic(RESILIENT_API_TOPIC.SAMPLE_DTO_LIST));
}
}
The code documentation
Take a look at the code documentation by opening the index.html file.
Test coverage report
Take a look at the test coverage by opening the index.html file.
Love the Resilience Client? Give our repo a star :star: :arrow_up:.