From the course: Calling REST APIs with Java

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Asynchronous API calls

Asynchronous API calls - Java Tutorial

From the course: Calling REST APIs with Java

Start my 1-month free trial

Asynchronous API calls

- [Instructor] In our previous examples, the requests that we sent to Azure Cognitive Services were sent synchronously. That means that the API call blocked the execution of our code. So here in line 69, once we sent the request over to the text analytics API, our code did not continue execution, it sat here and waited for that response to come back from the API. Now, we have other options in how we make this call. We can make the call asynchronous and when we make an asynchronous call, it's going to allow our code to continue executing while we wait on the response from the API and we can do this with the new Java 11 HTTP client. Let's take a look at this in action. So the first thing that we'll need to do is change from using the send method on the HTTP client to using the sendAsync method, and the mechanics of this method work a little bit differently. We're no longer going to return the HttpResponse, so I'm going…

Contents