import { Task } from './../model/task' ; import { Injectable } from '@angular/core' ; import { Headers , Http , Request , RequestMethod , Response } from '@angular/http' ; import { Observable } from 'rxjs/Observable' ; @ Injectable ( ) export class TasksService { API_BASE_URL : string = 'http://localhost:3001' ; API_TASKS_URL : string = `${ this . API_BASE_URL }/tasks` ; constructor ( private http ) { } loadTasks ( ) { return this . http . get ( this . API_TASKS_URL ) . map ( ( res ) => res . json ( ) ) ; } createTask ( body ) { return this . http . post ( this . API_TASKS_URL , this . getBody ( body ) ) . map ( ( res ) => res . json ( ) ) ; } updateTask ( taskId , body ) { return this . http . put ( `${ this . API_TASKS_URL }/${ taskId }` , this . getBody ( body ) ) . map ( ( res ) => res . json ( ) ) ; } deleteTask ( taskId ) { return this . http . delete ( `${ this . API_TASKS_URL }/${ taskId }` ) . map ( ( res ) => res . json ( ) ) ; } private getBody ( body ) { return body ; } }