Making parallel HTTP requests
Think about the scenario in which you have to add a new web page in your application, and to render the web page, you have to call more than one API because you need multiple pieces of data from multiple sources (list of products, list of news, list of links, etc.) for the same page. In the scenario with one web page that needs data from multiple API calls, you could perform the HTTP requests simultaneously to reduce the response time of the page.
For this example, to simplify the explanation, we will avoid using the controller and the view. We are going to collect JSON responses from APIs and then we will merge the responses into one JSON response. The important aspect to focus on is the mechanism of calling HTTP requests to third-party HTTP services because our goal is to understand how to make the HTTPS call concurrently.
To simulate the HTTP service, we are going to create two new routes:
api/sentence
: An API endpoint that replies with...