From the course: Calling REST APIs with Java

Unlock the full course today

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

Java HTTP Client

Java HTTP Client - Java Tutorial

From the course: Calling REST APIs with Java

Start my 1-month free trial

Java HTTP Client

- Java 11 introduced a new HTTP client that makes it much easier to call an API with Java. Here's an example of an API request to Azure Cognitive Services that was written prior to Java 11. You can see there's quite a bit of code and it required us to do things like handle the IO for a request or a response body. This often led to errors where we would forget to close our resources. Luckily the HTTP client makes it much simpler in Java 11. It also supports HTTP/2, so you can benefit from the performance enhancements delivered by that new version of the protocol. To see how it works, let's build a call to another API within Azure Cognitive Services. Within the Azure entities test class, we'll create a unit test that calls the named entities recognition endpoint on the text analytics API. This endpoint can extract people, places, and organizations from the texts that we provide. To help us out, I've added a number of…

Contents