Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-http-resilience

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-http-resilience

Angular HttpInterceptors that provide resiliency capabilities

  • 0.4.4
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

License CI Workflow codecov

ngx-http-resilience

Angular HttpInterceptor that provides resiliency capabilities

Getting Started

Installation

npm install ngx-http-resilience

Usage

Interceptor Functions

// app.config.ts
import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { ApplicationConfig } from '@angular/core';
import { HttpVisibilityInterceptorError, HttpVisibilityInterceptorHttpEvent, createHttpVisibilityInterceptorFn } from 'ngx-http-resilience';
import { Subject } from 'rxjs';

export const httpEvents$ = new Subject<HttpVisibilityInterceptorHttpEvent<unknown>>();
export const errors$ = new Subject<HttpVisibilityInterceptorError>();
const visibilityInterceptor = createHttpVisibilityInterceptorFn({
  httpEvents$,
  errors$,
});

export const appConfig: ApplicationConfig = {
  providers: [provideHttpClient(withInterceptors([visibilityInterceptor]))],
};

Interceptor Service

// app.config.ts
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { ApplicationConfig } from '@angular/core';
import { HttpVisibilityInterceptorService } from 'ngx-http-resilience';

export const visibilityInterceptorService = new HttpVisibilityInterceptorService();

export const httpInterceptorProviders = [
  {
    provide: HTTP_INTERCEPTORS,
    useValue: visibilityInterceptorService,
    multi: true,
  },
];

export const appConfig: ApplicationConfig = {
  providers: [httpInterceptorProviders],
};

Visibility

The visibility interceptor provides a stream of http events and errors. This can be used to modify an apps behaviour, such as letting a user know that there are network connectivity issues.

Retry

The retry interceptor allows for retrying failed requests. For example retrying requests that failed due to network connectivity issues.

Every retry interceptor has a retry policy, which determines:

  • Which requests it handles (shouldHandleRequest)
  • Which errors it handles (shouldHandleError)
  • How much time to wait between retries (delay)

Optionally it can also specify a:

  • Maximum number of retries (maxRetries)
  • Maximum time to wait for success (maxDuration)
FunctionService

provideHttpClient(
  withInterceptors([
    createHttpRetryInterceptorFn({
      shouldHandleRequest: matchPattern({ url: /example.com/ }),
      shouldHandleError: withStatusCodes(STANDARD_RETRYABLE_STATUS_CODES),
      delay: constantDelay(10, true),
    })
  ])
),
TODO

Keywords

FAQs

Package last updated on 20 May 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc