const BASE_URL = "http://192.168.68.177:8000" export default { async getMeals(from, to) { const response = fetch(BASE_URL + "/meals?from=" + from.toISOString() + "&to=" + to.toISOString()); return response.json(); }, async getMeal(id) { var response = await fetch(BASE_URL + `/meals/${encodeURIComponent(id)}`); return response.json(); }, async searchRecipes(query) { const response = await fetch(BASE_URL + "/recipes?q=" + encodeURIComponent(query)); return response.json(); }, async parseRecipe(url) { const response = await fetch(BASE_URL + `/recipes/parse?url=${encodeURIComponent(url)}`); return response.json(); }, async getRecipe(id) { const response = await fetch(BASE_URL + `/recipes/${encodeURIComponent(id)}`); return response.json(); }, async parseProduct(ingredient, url) { const body = { url, tags: [ingredient.name, ingredient.line], }; const response = await fetch(BASE_URL + "/products", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); return response.json(); }, async parseIngredients(lines) { const params = lines.map(line => "ingredients=" + encodeURIComponent(line)).join("&"); const response = await fetch(BASE_URL + "/recipes/ingredients/parse?" + params); return response.json(); }, async saveRecipe(recipe) { const response = await fetch(BASE_URL + "/recipes", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(recipe), }); return response.json(); }, async saveMeal(meal) { const response = await fetch(BASE_URL + "/meals", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(meal), }); return response.json(); }, }