blob: 04097a656880c7916dc39ee833c36377738fb8aa [file] [log] [blame]
Matteo Scandolo43ffb672016-12-02 14:49:58 -08001/// <reference path="../../../../typings/index.d.ts"/>
2
3// Imports
4import {AppConfig} from '../../config/app.config';
5import { Injectable } from '@angular/core';
6import { Http, Response, Headers, RequestOptions } from '@angular/http';
7import {Observable} from 'rxjs/Rx';
8
9// Import RxJs required methods
10import 'rxjs/add/operator/map';
11import 'rxjs/add/operator/catch';
12
13@Injectable()
14export class CoreService {
15 // Resolve HTTP using the constructor
16 constructor (private http: Http) {}
17 // private instance variable to hold base url
18 private baseUrl = AppConfig.apiEndpoint;
19
20 // Fetch all existing comments
21 getCoreEndpoints() : Observable<any[]> {
22
23 // ...using get request
24 return this.http.get(`${this.baseUrl}/core/`)
25 // ...and calling .json() on the response to return data
26 .map((res:Response) => res.json())
27 //...errors if any
28 .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
29
30 }
31}