I am trying fetch Yelp data in my express backend and then store the data into the state to use in the frontend, but when I try to make the request, it will throw me error with AxiosError: Request failed with status code 400
in the backend terminal.
This is the code in my backend express routes/api folder for yelp, the item would be the the name of the term that pass in from frontend.
const express = require('express');
const router = express.Router();
const axios = require('axios');
router.post('/:item', async (req, res) => {
axios.get("https://api.yelp.com/v3/businesses/search",{
headers: {
Authorization: `Bearer ${api_key}`
},
params: {
term: req.params.item,
location: "nyc"
}
})
.then(response => {
return res.json(response.data.businesses)
})
.catch(err => {
console.log(err)
})
})
module.exports = router;
I tried to make the fetch from fronetend with cors anywhere but it’s too easy to hit the limit, so I wanna make the request from the backend.