matrix-dimension/web/app/shared/services/authed-api.ts

27 lines
882 B
TypeScript
Raw Normal View History

import { Observable } from "rxjs/Observable";
2017-12-22 23:08:10 -05:00
import { SessionStorage } from "../SessionStorage";
2019-06-29 02:21:56 -04:00
import { HttpClient } from "@angular/common/http";
export class AuthedApi {
2019-06-29 02:21:56 -04:00
constructor(protected http: HttpClient) {
}
2019-06-29 02:21:56 -04:00
protected authedGet<T>(url: string, qs?: any): Observable<T> {
if (!qs) qs = {};
2017-12-22 23:08:10 -05:00
qs["scalar_token"] = SessionStorage.scalarToken;
2019-06-29 02:21:56 -04:00
return this.http.get<T>(url, {params: qs});
}
2019-06-29 02:21:56 -04:00
protected authedPost<T>(url: string, body?: any): Observable<T> {
if (!body) body = {};
const qs = {scalar_token: SessionStorage.scalarToken};
2019-06-29 02:21:56 -04:00
return this.http.post<T>(url, body, {params: qs});
}
2019-06-29 02:21:56 -04:00
protected authedDelete<T>(url: string, qs?: any): Observable<T> {
if (!qs) qs = {};
qs["scalar_token"] = SessionStorage.scalarToken;
2019-06-29 02:21:56 -04:00
return this.http.delete<T>(url, {params: qs});
}
}