munch-ease-frontend/src/data.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-01-13 02:00:15 +00:00
const BASE_URL = "http://localhost:8000"
export default {
getMeals() {
return fetch(BASE_URL + "/meals")
.then(response => response.json())
},
getMeal(id) {
return fetch(BASE_URL + `/meals/${encodeURIComponent(id)}`)
.then(response => response.json())
},
getRecipes() {
},
parseRecipe(url) {
return fetch(BASE_URL + `/recipes/parse?url=${encodeURIComponent(url)}`)
.then(response => response.json())
},
parseProduct(ingredient, url) {
const body = {
url, tags: [ingredient.name, ingredient.line],
}
return fetch(BASE_URL + "/products", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(body),
}).then(response => response.json())
},
parseIngredients(lines) {
const params = lines.map(line => "ingredients=" + encodeURIComponent(line)).join("&");
return fetch(BASE_URL + "/recipes/ingredients/parse?" + params)
.then(response => response.json())
}
}