import { Inject } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs';

export class BooksService{
  constructor(@Inject(Http) http) {
    this.http = http;
  }                  
  
  get() {
    // return this.http.get('books')
    //   .map(response => this.extractData(response))
    //   .catch(err => Observable.throw(err.message));
    
    return this.http.get('books')
       .toPromise()
       .then(response => this.extractData(response));
  }
  
  extractData(response) {
    return response.json();
  }
}