DEV Community

Cover image for How to call api within api
imdipu89
imdipu89

Posted on

How to call api within api

i have two api first one is restaurant which i succesfully run now the product id mean the breakfast and sweet api is different now that breakfast sweet api will automatically call according to sell id mean restaurant id i am not able to solve this problem pls help me i am using react js for that and i am using axios for calling api

code for restaurant
const getProductInfo = () => {
const prodId = params.id;
console.log("this is proid",prodId)
const apiUrl = /restaurant/${prodId} ;
axios
.get(apiUrl)
.then((res) => {
console.log("api info res", res.data.vendorDataID);
setUser(res.data.vendorDataID);
})
.catch((err) => {
console.log("error", err);
});

Top comments (1)

Collapse
 
prosenjit98 profile image
prosenjit98

const getProductInfo = () => {
const prodId = params.id;
console.log("this is proid",prodId)
const apiUrl = /restaurant/${prodId} ;
axios
.get(apiUrl)
.then((res) => {
console.log("api info res", res.data.vendorDataID);
setUser(res.data.vendorDataID);
return axios.get(...); // using response.data
}).then((response) => {
console.log('Response', response);
}).catch((err) => {
console.log("error", err);
});