Created
July 27, 2020 03:37
-
-
Save cyberyugun/9f6dbe78c188feb73a5a46b9ae89529c to your computer and use it in GitHub Desktop.
blablalbalbal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class RestApiService { | |
constructor(private http: HttpClient) { } | |
getHeaders() { | |
const token = localStorage.getItem('token'); | |
return token ? new HttpHeaders().set('Authorization', token) : null; | |
} | |
get(link: string) { | |
return this.http.get(link, { headers: this.getHeaders() }).toPromise(); | |
} | |
post(link: string, body: any) { | |
return this.http.post(link, body, { headers: this.getHeaders() }).toPromise(); | |
} | |
url; | |
link(a){ | |
this.url = a; | |
} | |
link_url() { | |
return this.url; | |
} | |
getDataURL() { | |
return this.http.get(`${this.link_url()}`, { headers: this.getHeaders() }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment