3.0.2 • Published 6 years ago

angular-interceptors v3.0.2

Weekly downloads
-
License
GPL-3.0
Repository
-
Last release
6 years ago

angular-interceptors

Useful interceptors for Angular

Installation

npm install angular-interceptors --save

Usage

Cache Interceptor

Cache all HTTP GET requests.

GET requests with a disable-cache header will not be cached.

import {CacheInterceptorModule} from 'angular-interceptors';

@NgModule({
  imports: [
    CacheInterceptorModule.forRoot(3 * 1000) // Max age in milliseconds. In this case 3 seconds. Defaults to 5 seconds.
  ]
})

Example:

this.http.get('https://some.url'); // --> https://some.url
this.http.get('https://some.url');

setTimeout(() => { 
  this.http.get('https://some.url'); // --> https://some.url
}, 5001);

Ensure Https Interceptor

Change http:// to https:// in HTTP request urls.

import {EnsureHttpsInterceptorModule} from 'angular-interceptors';

@NgModule({
  imports: [
    EnsureHttpsInterceptorModule.forRoot()
  ]
})

Example:

this.http.get('http://some.url');  // --> https://some.url
this.http.get('https://some.url'); // --> https://some.url

Prefix Url Interceptor

Prefix HTTP request urls.

import {PrefixUrlInterceptorModule} from 'angular-interceptors';

@NgModule({
  imports: [
    PrefixUrlInterceptorModule.forRoot('https://some.url') // prefix
  ]
})

Example:

this.http.get('/api/user'); // --> https://some.url/api/user

InjectionTokens

The configurations are also available as InjectionTokens:

InjectionTokenModule
MAX_AGE_MSCacheInterceptorModule
PREFIXPrefixUrlInterceptorModule
import {MAX_AGE_MS, PREFIX} from 'angular-interceptors';

@NgModule({
  providers: [
    {provide: MAX_AGE_MS, useValue: 3 * 1000},
    {provide: PREFIX, useValue: 'https://some.url'}
  ]
})
3.0.2

6 years ago

2.1.0

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago