You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Daidokoro/daidokoro/src/app/service/ingredient.service.ts

27 lines
759 B

import { Injectable } from '@angular/core';
import { Ingredient } from "../model/ingredient.model";
import { Observable } from "rxjs";
import { HttpClient } from "@angular/common/http";
@Injectable({
providedIn: 'root'
})
export class IngredientService {
private apiUrl = 'https://664ba07f35bbda10987d9f99.mockapi.io/api/ingredients';
constructor(private http: HttpClient) { }
getAll(): Observable<Ingredient[]> {
return this.http.get<Ingredient[]>(this.apiUrl);
}
add(ingredient: Ingredient): Observable<Ingredient> {
return this.http.post<Ingredient>(this.apiUrl, ingredient);
}
update(ingredient: Ingredient): Observable<Ingredient> {
return this.http.put<Ingredient>(`${this.apiUrl}/${ingredient.id}`, ingredient);
}
}