I am working on a react js project and needs to fetch the data from the API.
I am using the fetch()
to get the data.
Here, is my code.
fetch('https://sandboxapi.ampcome.com/api/gokhana/restaurant/categorized', {
method: 'GET',
headers: {
'Authorization': 'WqQg2jqLWVIO5JBmQ1LYHU8w41FdzLEsCB6yP1Tw2AFHf2w5KWRkMBV8KAgY6Kl5'
},
qs: {
geopoint: {
near: {
lat: 12.9699,
lng: 77.6499
},
maxDistance: 50,
unit: 'kilometers'
},
categories: ['trending', 'newaddition', 'popular'],
outlettypes: ['restaurant', 'foodcourt'],
clientapp: 'gokhanacustomer'
}
})
.then(res => res.json())
.then(res => console.log(res));
Everything is fine, but this return the empty array. There is a lot of data but it returns an empty array.
I tried the same with axios
and it fetches data, I am unable to figure out the exact issue in fetch()
I need to compare the working of axios
and fetch that is why I need to test it by both the ways.