blob: 04097a656880c7916dc39ee833c36377738fb8aa [file] [log] [blame]
/// <reference path="../../../../typings/index.d.ts"/>
// Imports
import {AppConfig} from '../../config/app.config';
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import {Observable} from 'rxjs/Rx';
// Import RxJs required methods
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
@Injectable()
export class CoreService {
// Resolve HTTP using the constructor
constructor (private http: Http) {}
// private instance variable to hold base url
private baseUrl = AppConfig.apiEndpoint;
// Fetch all existing comments
getCoreEndpoints() : Observable<any[]> {
// ...using get request
return this.http.get(`${this.baseUrl}/core/`)
// ...and calling .json() on the response to return data
.map((res:Response) => res.json())
//...errors if any
.catch((error:any) => Observable.throw(error.json().error || 'Server error'));
}
}