So I'm building a Flask API, and I have a GET route that basically sends 5 requests to another API to gather data that I'm then merging and returning.
Like so:
results = [requests.get('http://localhost:9000/ss/1'),
requests.get('http://localhost:9000/ss/2'),
requests.get('http://localhost:9000/ss/3'),
requests.get('http://localhost:9000/ss/4'),
requests.get('http://localhost:9000/ss/5')]
The problem is each request takes about 2 seconds, so it takes 10 seconds for this to go down. How can I make all the requests async using different threads so it will take around 2 seconds overall? And then how do I tell the API to start merging them when theyre all loaded?
Any help is GREATLY appreciated!