I’m working on a React Native app and I’m having trouble getting RapidAPI to work properly. My app used to fetch user information from a simple JSON endpoint like this:
async loadUserData() {
try {
const result = await fetch('mysite.com/userinfo.json');
const userData = await result.json();
this.setState({
loading: false,
users: userData,
});
}
catch (err) {
console.log(err);
}
}
I want to switch to RapidAPI for better security but my current attempt just shows a blank screen:
async loadUserData() {
try {
const result = await fetch('dice-roll-api.p.rapidapi.com/roll', {
"method": "GET",
"headers": {
"x-rapidapi-host": "mysite.com",
"x-rapidapi-key": 'abc123def456ghi789jkl012mno345pqr678stu901vwx234yz'
}
});
const userData = await result.json();
this.setState({
loading: false,
users: userData,
});
}
catch (err) {
console.log(err);
}
}
What am I doing wrong here? The app worked fine before but now it’s not loading any data at all.