import { HttpClient } from "@angular/common/http"; import { Injectable, Injector, isDevMode } from "@angular/core"; import { Router } from "@angular/router"; @Injectable({ providedIn: 'root' }) export class Sdk { get base() { if (isDevMode()) { return `http://localhost:8081/` } else { return `/` } } get router() { return this.injector.get(Router) } get http() { return this.injector.get(HttpClient) } constructor(private injector: Injector) { } get(path: string, params: any = {}) { return this.http.get(this.createUrl(path), { params }) } getUser() { let data = localStorage.getItem('current') || ''; try { return JSON.parse(data) } catch (e) { return {} } } post(path: string, body: any) { return this.http.post(this.createUrl(path), body) } goto(path: string) { this.router.navigate(['rest'], { queryParams: { path: this.createUrl(path) } }) } createUrl(path: string) { return `${this.base}${path}` } }