I am trying to get data from the yelp api,
I have a fetching function that looks like this:
export function fetchRestaurants (term) {
const endpoint = `businesses/search?term=${term}&location=NYC`
return fetch(endpoint, {
headers: new Headers({
'Authorization': 'Bearer '+'oSJvaTmFtYVCEJcMsLFA4uRljDOILtEfp0sTWflSWclozapMP1rCZ6uttKPOoYnrdUGcTXI0ztOf3rTPVSBRa1JjngqcoTKD30YUp7yKxhZCNzS4bsZV_DqzzkAwXXYx',
}),
})
.then((res) => {
console.log(res)
res.json()
})
.then((data) => {
console.log(data)
// this is undefined!
return data
})
}
the respose is 200
on the first then
and looks like this:
Response {type: "basic", url: "http://localhost:3000/businesses/search?term=pizza&location=NYC", redirected: false, status: 200, ok: true, …}
type: "basic"
url: "http://localhost:3000/businesses/search?term=pizza&location=NYC"
redirected: false
status: 200
ok: true
statusText: "OK"
headers: Headers {}
body: (...)
bodyUsed: true
But then i try to do a .json
on it on the second then
, and when i try to log it its undefined.
Any ideas on how to get the actual data? Thanks