import { Observable } from "rxjs/Observable" ; import { Injectable } from "@angular/core" ; import { Http , RequestOptionsArgs , RequestOptions , Response , Headers } from "@angular/http" ; const mergeAuthToken = ( options = { } ) => { let newOptions = new RequestOptions ( { } ) . merge ( options ) ; let newHeaders = new Headers ( newOptions . headers ) ; const jwt = localStorage . getItem ( 'jwt' ) ; if ( jwt ) { newHeaders . set ( 'authorization' , `Bearer ${ jwt }` ) ; } newOptions . headers = newHeaders ; return newOptions ; } ; @ Injectable ( ) export class JsonHttp { constructor ( private http ) { } get ( url , options ? ) { return this . http . get ( url , mergeAuthToken ( options ) ) ; } post ( url , body , options ? ) { return this . http . post ( url , body , mergeAuthToken ( options ) ) ; } put ( url , body , options ? ) { return this . http . put ( url , body , mergeAuthToken ( options ) ) ; } delete ( url , options ? ) { return this . http . delete ( url , mergeAuthToken ( options ) ) ; } patch ( url , body , options ? ) { return this . http . patch ( url , body , mergeAuthToken ( options ) ) ; } head ( url , options ? ) { return this . http . head ( url , mergeAuthToken ( options ) ) ; } }