Consuming RESTful services with the MicroProfile Rest Client
Thus far, we've covered how we can design elaborate RESTful services and how we can easily transform JSON into Java objects and vice versa. Next up, we need to consume those services using the client APIs. In a microservice architecture, RESTful clients are critical for invoking remote services.
JAX-RS Client APIs
One way to consume RESTful services is with the JAX-RS Client APIs. Similar to JSON-P (as opposed to JSON-B), these APIs tend to be more programmatic with more control over individual options, such as headers, path construction, and so on. Let's take a look at some code using the thesaurus example from earlier in this chapter, as follows:
String uri = "http://localhost:9080/rest/thesaurus"; Client client = ClientBuilder.newBuilder().build(); WebTarget target = client.target(uri).path(word); Builder builder = target.request(MediaType.TEXT_PLAIN); try (Response response = builder.get(...