Client API
JAXRS has a Client API which is used for accessing web resources and also integrates with providers. When running microservices or writing tests, the Client API serves as a tool for invoking target web resources. To work with the API, we must first obtain an instance of Client
using the ClientBuilder.newClient
method. Using the fluent API, a request is created and submitted by chaining method invocations whose names should be self-descriptive:
Client client = ClientBuilder.newClient(); Response res = client.target("http://somewhere.org/hello") .queryParam("param","..."); .request("application/json") .header("X-Header","...") .get();
Both Client
and WebTarget
provide for registering filters and interceptors on the client-side. The API can also be utilized for building complex URI paths, which makes it fairly handy when building targets, as shown in the next section.
Targets
When resource URIs have complex paths to be...