'Ensure that API calls are efficient
I'm integrating with the Sport Radar API. This is a pretty great API but I'm noticing it doesn't have a particular Endpoint that I was hoping to leverage.
I noticed that the API does not have a Players index call. In order to get all the players in the league you have to go through this process (Confirmed by the API team)
1) Call an endpoint that lists the ids of each team in the league.
2) For each Team id call an endpoint that gets each team and lists each player for each team.
All in all that is over 30 API requests for each time I need to run a fairly common function.
MY CURRENT SOLUTION:
Store the Players in the database. So instead of reaching out through the API every time I need to list the players. I can just make a DB query for the players. This solution seems heavy handed though, I'd like for my application to not have to keep track of the players.
MY QUESTION
What are some ways of solving this problem? Again the questions is: What are ways of avoiding many api calls in order to get common data? Is the best solution just to make the 30 api call each time? Thank you!
Solution 1:[1]
I am working with the sport radar API and we had a similar problem, to solve it we use a cache to have this information faster and filtered, basically we connect a redis and run a cron in a service that updates the data (in our case each 24 hours).
Solution 2:[2]
You can use new lines and the unicode upperscore.
questions = [q1, q2]
nr_of_digits = 2
for q in questions:
q = list(map(str,q))
print(" " + q[0] + "\n" + "+" + q[1] + "\n" + u'\u0305' * (nr_of_digits + 1) + "\n")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lveliz |
| Solution 2 | tomasantunes |
