Hey guys,
Currently I am using React with Vite to make a website, that shows information from the api. However because of the CORS policy error, I need to move my api requests from react to some kind of server. What would you recommend using with react for a back-end server side ? I tried to research and it seems that it is possible for example to use like Python flask, nodejs, nestjs. What would you recommend for me to do, as I am a bit lost here 😄 . Thanks. I'm a bit bettter with python than with javascript
#Back-end with React
16 messages · Page 1 of 1 (latest)
ok just decided to do it both ways and see what i like better 😄
I would recommend node because it is pretty much javascript but if you are better with python then go ahead and use it :). Have fun!
I agree with Hello above -- use what you're comfortable with as if will help if errors occur and you need to debug stuff. ✨✨
@soft cedar Just out of curiosity, which API are you trying to fetch data from and how are you trying to do it? If you're just fetching data from a third-party API you shouldn't need to go through a dedicated server.
riot games api. It provides you with a specific api key code, and the requests per minute are limited
so far like this:
fetch(`https://euw1.api.riotgames.com/lol/summoner/v4/summoners/by-name/${playerNamesArray[i]}?api_key=${apiKey}`)
.then(res => res.json())
.then(data => setPlayerInfo((prevState) => [...prevState, data]))
}
}, [])```
That's fairly standard for APIs. What happens when you run that code?
if i put to many players i get cors policy error
So if you try just a single player the fetch request works fine?
When the error happens, what error code are you getting from the request? You can see this in the browser web tools "network" panel.
If fetching a single player works, but fetching multiple players fails, chances are you are getting rate limited on the API (this should result in a 429 error code) - Using a backend server for the fetch requests isn't going to magically by-pass the rate limit.
yep im getting 429, so do u know what are the options ? delaying the requests a bit or any other way ?:D
RATE LIMITS
20 requests every 1 seconds(s)
100 requests every 2 minutes(s)
@mighty notch ok with a delay it works, thanks for the info
Yeah adding a delay helps, as well as having more control over the API calls. For example if the call is executed from the user pressing the button you can disable the button for a number of seconds after it's pressed to stop the user spamming fetch calls.