import { HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { HttpBaseService } from './http-base.service'; @Injectable() export class DataService { constructor(private httpClient: HttpBaseService) {} get(url: string, token?: string): Observable { const headers = this.prepareHeaders(token); return this.httpClient.get(url, { headers, }); } post(url: string, body: any, headersParams?: HttpHeaders) { const headers = headersParams || this.prepareHeaders(); return this.httpClient.post(url, body, { headers }); } private prepareHeaders(token?: string) { let headers = new HttpHeaders(); headers = headers.set('Accept', 'application/json'); if (!!token) { headers = headers.set('Authorization', 'Bearer ' + decodeURIComponent(token)); } return headers; } }