Home > Mobile >  how to make multiple fetch request in a single fetch API. Javacsript
how to make multiple fetch request in a single fetch API. Javacsript

Time:02-05

I have an API link where I need to check the price of certain items. For example, Only change in the fetch url is the items. is there any easy way to do it in one fetch or using any loop

www.apirequest/item1/ps2
www.apirequest/item2/ps2
www.apirequest/item3/ps2
www.apirequest/item4/ps2
www.apirequest/item5/ps2

CodePudding user response:

You need to pass the item name/id in body or you can also grap that from params. Then in the api point you can use fetch or axios to make api request.


const axios = require("axios");

app.post("/api/test", async (req, res) => {

  const { param } = req.body // you can use query params

  await axios.get(`www.apirequest/item1/${param}`).then((result)=>{
console.log(result)
})

  res.send("okay");
});


  • Related