ngx-http-resilience
Advanced tools
Comparing version 0.0.1 to 0.1.2
@@ -1,1 +0,2 @@ | ||
export * from './lib/ngx-http-resilience.module'; | ||
export * from './lib/retry'; | ||
export * from './lib/visibility'; |
{ | ||
"name": "ngx-http-resilience", | ||
"version": "0.0.1", | ||
"version": "0.1.2", | ||
"description": "Angular HttpInterceptors that provide resiliency capabilities ", | ||
"keywords": [ | ||
"angular", | ||
"http", | ||
"interceptor", | ||
"resilience", | ||
"retry", | ||
"circuit-breaker" | ||
], | ||
"license": "MIT", | ||
"peerDependencies": { | ||
@@ -5,0 +15,0 @@ "@angular/common": "^16.2.0", |
@@ -0,7 +1,97 @@ | ||
![License](https://img.shields.io/github/license/ebh/ngx-http-resilience) | ||
[![CI Workflow](https://github.com/ebh/ngx-http-resilience/actions/workflows/ci.yml/badge.svg)](https://github.com/ebh/ngx-http-resilience/actions/workflows/ci.yml) | ||
[![codecov](https://codecov.io/gh/ebh/ngx-http-resilience/graph/badge.svg?token=m6R2XL7nDP)](https://codecov.io/gh/ebh/ngx-http-resilience) | ||
# ngx-http-resilience | ||
This library was generated with [Nx](https://nx.dev). | ||
Angular HttpInterceptor that provides resiliency capabilities | ||
## Running unit tests | ||
# Getting Started | ||
Run `nx test ngx-http-resilience` to execute the unit tests. | ||
## Installation | ||
```shell | ||
npm install ngx-http-resilience | ||
``` | ||
## Usage | ||
### Interceptor Functions | ||
```typescript | ||
# | ||
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 | ||
```typescript | ||
# | ||
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. | ||
```typescript | ||
``` | ||
### 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`) | ||
| Function | Service | | ||
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | | ||
| <pre><br/>provideHttpClient(<br/> withInterceptors([<br/> createHttpRetryInterceptorFn({<br/> shouldHandleRequest: matchPattern({ url: /example.com/ }),<br/> shouldHandleError: withStatusCodes(STANDARD_RETRYABLE_STATUS_CODES),<br/> delay: constantDelay(10, true),<br/> })<br/> ])<br/>),</pre> | TODO | |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
108953
53
0
981
98
1