Background:Are you still using Apache HTTP client or Java URL connection to speak with REST service? Then this article is for you. JAX-RS specification has released with new client API to communicate with RESTful services. Here you can see how you can use JAX-RS client API for your communication.
As a first step, we have to create a web target in-order to talk to our web services. Using the ClientBuilder, we should create a Client object.
From the client object we can create WebTarget object like below,
Once we get the webTarget object, we are ready to communicate with the REST service. From the webTarget object we can invoke the respective REST methods...
Just to get the JSON string from the response, we have passed the object type (String.class) to the readEntity method. If we get any complex object type, we can still use them.
I hope you will enjoy this article. Please give your comments or feedback if you have any... We will meet shortly with another article.