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()) }, saveRecipe(recipe) { return fetch(BASE_URL + "/recipes", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(recipe), }).then(response => response.json()) } }