services.ts 724 B

1234567891011121314151617181920212223242526272829
  1. import axios, { AxiosPromise } from 'axios';
  2. import Recipe from 'types/recipes';
  3. //@ts-ignore
  4. const API: string = process.env.REACT_APP_API_RECIPES;
  5. export const getRecipes = (query: any): Promise<Recipe[]> =>
  6. axios.get(`${API}/all`)
  7. .then(response => response.data);
  8. export const saveRecipe = (recipe: Recipe): Promise<any> =>
  9. axios.post(`${API}`, recipe)
  10. export const getRecipeById = (id: string): Promise<Recipe> =>
  11. axios.get(`${API}/id/${id}`)
  12. .then(response => response.data)
  13. export const scrapeRecipe = (url: string): Promise<Recipe> =>
  14. axios.post(
  15. `${API}/scrape`,
  16. { url }
  17. ).then(response => response.data);
  18. export default {
  19. getRecipes,
  20. getRecipeById,
  21. scrapeRecipe,
  22. saveRecipe
  23. }