HttpClient Interceptor

import {Injectable} from '@angular/core';

import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http';

import {Observable} from 'rxjs/Observable';


@Injectable()

export class APIInterceptor implements HttpInterceptor {

 intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {


  const apiReq = req.clone({ url: `your-api-url/${req.url}` });

  return next.handle(apiReq);

 }

}


providers: [{

   provide: HTTP_INTERCEPTORS,

   useClass: APIInterceptor,

   multi: true,

  }

 ]

Sign In or Register to comment.