4.0.0 • Published 9 years ago

angular2-http-interceptor v4.0.0

Weekly downloads
81
License
MIT
Repository
github
Last release
9 years ago

angular2-http-interceptor

Http interceptor for angular2. Built with angular-library-starter

Features

  • Registering interceptors globally
  • Separate interceptors for requests and responses
  • Modify requests (even url) from request interceptors
  • Cancel requests from request interceptors
  • Modify responses from response interceptors
  • Interceptor Service is not coupled with Http Service
  • Choose between overriding original Http Service or keep it and still use interceptors
  • Support AOT.

Table of Contents

Installation

To install this library, run:

$ npm install angular2-http-interceptor --save

Usage

First, write your interceptor.

import {Request, Response} from '@angular/http';
import {Inject} from '@angular/core';
import {Platform} from 'ionic-angular';

import {IHttpInterceptor} from 'angular2-http-interceptor';
export class AuthInterceptor implements IHttpInterceptor {
  constructor(@Inject(Platform) private platform: Platform) {
  }

  before(request: Request): Request {
    if (this.platform.is('cordova') && request.url.match(/^\/api-hk\//)) {
      request.url = `http://yulonh.com${request.url}`;
    }
    return request;
  }
}

Then add code HttpInterceptorModule.withInterceptors([AuthInterceptor]) in app.module.ts file.

...
import {HttpInterceptorModule} from 'angular2-http-interceptor';

@NgModule({
  ...
  imports: [
    ...
    HttpInterceptorModule.withInterceptors(      [{
                                                   deps: [Platform],
                                                   provide: HttpInterceptor,
                                                   useClass: AuthInterceptor,
                                                   multi: true
                                                 }])
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    ...
  ],
  providers: [...]
})
export class AppModule {

}

License

MIT © yulonh

4.0.0

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.8.0

9 years ago

1.6.7

9 years ago

1.6.6

9 years ago

1.6.5

9 years ago

1.6.4

9 years ago

1.6.3

9 years ago

1.6.2

9 years ago

1.6.1

9 years ago

1.6.0

9 years ago

1.5.9

9 years ago

1.5.8

9 years ago

1.5.7

9 years ago

1.5.6

9 years ago

1.5.5

9 years ago

1.5.4

9 years ago

1.5.3

9 years ago

1.5.2

9 years ago

1.5.1

9 years ago

1.5.0

9 years ago

1.4.9

9 years ago

1.4.8

9 years ago

1.4.7

9 years ago

1.3.5

9 years ago

1.3.3

9 years ago

1.3.2

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.9

9 years ago

1.2.8

9 years ago

1.2.7

9 years ago

1.2.6

9 years ago

1.2.5

9 years ago

1.2.4

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

10 years ago

1.1.8

10 years ago

1.1.7

10 years ago

1.1.6

10 years ago

1.1.5

10 years ago

1.1.4

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago