Skip to content

Instantly share code, notes, and snippets.

@cyberyugun
Created July 27, 2020 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberyugun/9f6dbe78c188feb73a5a46b9ae89529c to your computer and use it in GitHub Desktop.
Save cyberyugun/9f6dbe78c188feb73a5a46b9ae89529c to your computer and use it in GitHub Desktop.
blablalbalbal
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