diff --git a/src/sxc-api.service.ts b/src/sxc-api.service.ts new file mode 100644 index 0000000..c2d1563 --- /dev/null +++ b/src/sxc-api.service.ts @@ -0,0 +1,45 @@ +import { Injectable } from "@angular/core"; +import { Http, Response, Headers } from "@angular/http"; +import { Observable } from "rxjs"; + +@Injectable() +export class ApiResourceFactory { + constructor( + private http: Http + ) { } + + resource(ctrl: string) { + return new ApiResource(this.http, ctrl); + } +} + +export class ApiResource { + constructor( + private http: Http, + private ctrl: string + ) { } + + get(id: number = null): Observable { + let url = `/DesktopModules/2sxc/API/app-api/${this.ctrl}`; + if (id) url += `/${id}`; + let headers = new Headers(); + return this.http.get(url, { headers }) + .map(response => response.json()); + } + + post(body: any): Observable { + let url = `/DesktopModules/2sxc/API/app-api/${this.ctrl}`; + let headers = new Headers(); + return this.http.post(url, body, { headers }) + .map(response => response.json()); + } + + delete(id: number = null): Observable { + let url = `/DesktopModules/2sxc/API/app-api/${this.ctrl}`; + if (id) url += `/${id}`; + let headers = new Headers(); + return this.http.delete(url, { headers }) + .map(response => response.json()); + } + +} \ No newline at end of file