i wont to make class to handle fetch data from api, please help my trouble:
class Api{
static getAll(){
fetch("https://covid-193.p.rapidapi.com/statistics", {
"method": "GET",
"headers": {
"x-rapidapi-host": "covid-193.p.rapidapi.com",
"x-rapidapi-key": "c44a47562cmsh6ff0d107514bccfp146d00jsn876b11317ac5"
}
})
.then(function(response) {
return response.json()
})
.catch(function(err) {
console.log(err)
})
}
}
export default Api;
when i call Api.getAll() in app.js like this:
import Api from "./api.js"
console.log(Api.getAll())
its not console anything , just console undefine. but if i console inside .then() like this
.then(function(response) {
console.log(response.json())
the result in console is
undefine
result json
and if i change the key to get eror, the .catch() not work also.
thanks,