Skip to content
Snippets Groups Projects
Commit ef6c975b authored by zh393's avatar zh393
Browse files

migrated API to premium version

parent 195c0d1e
No related branches found
No related tags found
No related merge requests found
import React, { useEffect, useState } from 'react'
import { useParams } from "react-router-dom"
import axios from "axios"
import { Container, Typography } from '@mui/material';
import parse from 'html-react-parser';
var axios = require("axios").default;
function Recipe() {
const { id } = useParams();
const [data, setData] = useState([]);
useEffect(() => {
const params = new URLSearchParams({
apiKey: "4ce04e457c8348cfaec8ee0c7100b2f8",
includeNutrition: true
})
let base_url = `https://api.spoonacular.com/recipes/${id}/information`
let url = base_url + "?" + params.toString()
let resp = axios({
url: url,
method: "get",
var options = {
method: 'GET',
url: `https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/${id}/information`,
params: { includeNutrition: 'true' },
headers: {
"Content-Type": "application/json"
'x-rapidapi-host': 'spoonacular-recipe-food-nutrition-v1.p.rapidapi.com',
'x-rapidapi-key': '9488865383msh30a38be9ec16e99p109d9bjsn9090d29ce12f'
}
})
};
axios.request(options).then(function (response) {
setData(response.data);
}).catch(function (error) {
console.error(error);
});
resp.then(r => setData(r.data));
}, []) // eslint-disable-line react-hooks/exhaustive-deps
let body = <Typography variant="p">Loading...</Typography>;
......
import { Container, Typography } from '@mui/material'
import axios from 'axios'
import React, { useState, useEffect } from 'react'
import { useLocation, Link } from "react-router-dom"
var axios = require("axios").default;
function Results() {
......@@ -12,27 +12,26 @@ function Results() {
let ingredientNames = ""
location.state.items.forEach(ingredient => ingredientNames += ingredient + ",");
ingredientNames = ingredientNames.slice(0, -1); // remove the last comma
const params = new URLSearchParams({
apiKey: "4ce04e457c8348cfaec8ee0c7100b2f8",
ingredients: ingredientNames
})
let base_url = "https://api.spoonacular.com/recipes/findByIngredients"
let url = base_url + "?" + params.toString()
let resp = axios({
url: url,
method: "get",
var options = {
method: 'GET',
url: 'https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/findByIngredients',
params: {
ingredients: ingredientNames,
number: '10',
ignorePantry: 'true',
ranking: '2'
},
headers: {
"Content-Type": "application/json"
'x-rapidapi-host': 'spoonacular-recipe-food-nutrition-v1.p.rapidapi.com',
'x-rapidapi-key': '9488865383msh30a38be9ec16e99p109d9bjsn9090d29ce12f'
}
})
resp.then(r => {
setRecipes(r.data);
})
};
axios.request(options).then(function (response) {
setRecipes(response.data);
}).catch(function (error) {
console.error(error);
});
}, []) // eslint-disable-line react-hooks/exhaustive-deps
const recipeComponent = recipes.map(recipe =>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment