added prediction prototype
This commit is contained in:
@ -25,19 +25,19 @@ export class ApiService {
|
||||
}
|
||||
|
||||
get<T>(url, f: (data?: T, err?, headers?) => void = () => {}) {
|
||||
this.requestErrorHandler<T>(this.http.get(this.host + url, this.options()), f);
|
||||
this.requestErrorHandler<T>(this.http.get(this.url(url), this.options()), f);
|
||||
}
|
||||
|
||||
post<T>(url, data = null, f: (data?: T, err?, headers?) => void = () => {}) {
|
||||
this.requestErrorHandler<T>(this.http.post(this.host + url, data, this.options()), f);
|
||||
this.requestErrorHandler<T>(this.http.post(this.url(url), data, this.options()), f);
|
||||
}
|
||||
|
||||
put<T>(url, data = null, f: (data?: T, err?, headers?) => void = () => {}) {
|
||||
this.requestErrorHandler<T>(this.http.put(this.host + url, data, this.options()), f);
|
||||
this.requestErrorHandler<T>(this.http.put(this.url(url), data, this.options()), f);
|
||||
}
|
||||
|
||||
delete<T>(url, f: (data?: T, err?, headers?) => void = () => {}) {
|
||||
this.requestErrorHandler<T>(this.http.delete(this.host + url, this.options()), f);
|
||||
this.requestErrorHandler<T>(this.http.delete(this.url(url), this.options()), f);
|
||||
}
|
||||
|
||||
private requestErrorHandler<T>(observable: Observable<any>, f: (data?: T, err?, headers?) => void) {
|
||||
@ -62,6 +62,15 @@ export class ApiService {
|
||||
});
|
||||
}
|
||||
|
||||
private url(url) {
|
||||
if (/http[s]?:\/\//.test(url)) {
|
||||
return url;
|
||||
}
|
||||
else {
|
||||
return this.host + url;
|
||||
}
|
||||
}
|
||||
|
||||
private options(): {headers: HttpHeaders, observe: 'body'} {
|
||||
return {headers: this.authOptions(), observe: 'response' as 'body'};
|
||||
}
|
||||
|
Reference in New Issue
Block a user