import { Injectable } from '@angular/core' ; import { Observable } from 'rxjs' ; import { HttpClient } from '@angular/common/http' ; @ Injectable ( ) export class BeerService { public API = 'http://192.168.1.48:8080' ; public BEER_API = this . API + '/beers' ; constructor ( public http ) { } getGoodBeers ( ) { return this . http . get ( this . API + '/good-beers' ) ; } get ( id ) { return this . http . get ( this . BEER_API + '/' + id ) ; } save ( beer ) { let result ; if ( beer [ 'href' ] ) { result = this . http . put ( beer . href , beer ) ; } else { result = this . http . post ( this . BEER_API , beer ) ; } return result . catch ( error => Observable . throw ( error ) ) ; } remove ( id ) { return this . http . delete ( this . BEER_API + '/' + id ) ; } }