{8.2.0-updated} juneau-rest-client
juneau-rest-client-{@property juneauVersion}.jar
org.apache.juneau.rest.client_{@property juneauVersion}.jar
Built upon the feature-rich Apache HttpClient library, the Juneau RestClient API adds support for fluent-style REST calls and the ability to perform marshalling of POJOs to and from HTTP parts.
Breaking apart the fluent call, we can see the classes being used:
RestClientBuilder
It additionally provides support for creating remote proxy interfaces using REST as the transport medium.
The classes are closely tied to Apache HttpClient, yet provide lots of additional functionality:
Instances of this class are built using the {@link oajr.client2.RestClientBuilder} class which can be constructed using the {@link oajr.client2.RestClient#create() RestClient.create()} method as shown above.
Clients are typically created with a root URI so that relative URIs can be used when making requests. This is done using the {@link oajr.client2.RestClientBuilder#rootUri(Object)} method.
The {@link oajr.client2.RestClient} class creates {@link oajr.client2.RestRequest} objects using the following methods:
The {@link oajr.client2.RestRequest} class creates {@link oajr.client2.RestResponse} objects using the following methods:
The distinction between the two methods is that {@link oajr.client2.RestRequest#complete() complete()} automatically consumes the response body and {@link oajr.client2.RestRequest#run() run()} does not. Note that you must consume response bodies in order for HTTP connections to be freed up for reuse! The {@link java.io.InputStream InputStreams} returned by the {@link oajr.client2.RestResponseBody} object are auto-closing once they are exhausted, so it is often not necessary to explicitly close them.
The following examples show the distinction between the two calls: