blob: a82e019758107b104385bd1704ad08c4ecc4cd40 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Recipes } from '../recipes';
@Injectable({
providedIn: 'root',
})
export class RecipesService {
private allRecipesAPI =
'https://www.themealdb.com/api/json/v1/1/search.php?f=a';
private recipeByIdAPI =
'https://www.themealdb.com/api/json/v1/1/lookup.php?i=';
private recipeByNameAPI =
'https://www.themealdb.com/api/json/v1/1/search.php?s=';
private recipeByIngredientAPI =
'https://www.themealdb.com/api/json/v1/1/filter.php?i=';
private recipeByCategoryAPI =
'https://www.themealdb.com/api/json/v1/1/filter.php?c=';
httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
constructor(private http: HttpClient) {}
getAllRecipes(): Observable<Recipes[]> {
return this.http.get<Recipes[]>(this.allRecipesAPI);
}
getRecipeById(id: number): Observable<Recipes[]> {
return this.http.get<Recipes[]>(this.recipeByIdAPI + id);
}
getRecipeByName(name: string): Observable<Recipes[]> {
return this.http.get<Recipes[]>(this.recipeByNameAPI + name);
}
getRecipeByIngredient(ingredient: string): Observable<Recipes[]> {
return this.http.get<Recipes[]>(this.recipeByIngredientAPI + ingredient);
}
getRecipeByCategory(category: string): Observable<Recipes[]> {
return this.http.get<Recipes[]>(this.recipeByCategoryAPI + category);
}
}
|