0.2.0 • Published 1 year ago

ngx-interceptors v0.2.0

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
1 year ago

ngx-interceptors

Common HTTP Interceptors for Angular Applications. Available as HTTP Inteceptor class or function.

Installation

Using npm: npm i ngx-interceptors

Using yarn: yarn add ngx-interceptors

Interceptors

Usage

Adding one or multiple interceptors to your application is done by registering them as providers. Either in your module class or for standalone projects in the bootstrap application function.

Module based project

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule
  ],
  providers: [
    { provide: HTTP_INTERCEPTORS, useClass: RetryInterceptor, multi: true }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Standalone project

HTTP Interceptor Class

bootstrapApplication(AppComponent, {
  providers: [
    provideHttpClient(
      withInterceptorsFromDi()
    ),
    { provide: HTTP_INTERCEPTORS, useClass: RetryInterceptor, multi: true }
  ]
})
  .catch((err) => console.error(err));

HTTP Interceptor Function

bootstrapApplication(AppComponent, {
  providers: [
    provideHttpClient(
      withInterceptors([retryInterceptor])
    )
  ]
})
  .catch((err) => console.error(err));

Configuration

Each interceptor comes with a custom configuration. You can overwrite the default configuration and provide your own values.

providers: [
    {
      provide: RETRY_INTERCEPTOR_CONFIG,
      useValue: {
        retries: 3,
        delay: 1000
      }
    }
  ]

If no or incomplete configurations are provided, the default values will be used.

0.2.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.4

1 year ago

0.0.1

1 year ago