Last active
February 14, 2018 08:02
-
-
Save krishna-acondy/6385657dc8d3423ba10a12c60d64f0f4 to your computer and use it in GitHub Desktop.
PizzaService example for a service using the HttpClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class PizzaService { | |
private url='http://pizzaService'; | |
private endpoint = 'pizzas'; | |
constructor( | |
protected httpClient: HttpClient) {} | |
public create(pizza: Pizza): Observable<Pizza> { | |
return this.httpClient | |
.post<Pizza>(`${this.url}/${this.endpoint}`, pizza); | |
} | |
public update(pizza: Pizza): Observable<Pizza> { | |
return this.httpClient | |
.put<Pizza>(`${this.url}/${this.endpoint}/${pizza.id}`, pizza); | |
} | |
read(id: number): Observable<Pizza> { | |
return this.httpClient | |
.get<Pizza>(`${this.url}/${this.endpoint}/${id}`); | |
} | |
list(): Observable<Pizza[]> { | |
return this.httpClient | |
.get<Pizza[]>(`${this.url}/${this.endpoint}`); | |
} | |
delete(id: number) { | |
return this.httpClient | |
.delete(`${this.url}/${this.endpoint}/${id}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment