Interface Invocation.Builder

All Superinterfaces:
SyncInvoker
Enclosing interface:
Invocation

public static interface Invocation.Builder extends SyncInvoker
A client request invocation builder. The builder, obtained via a call to one of the request(...) methods on a resource target, provides methods for preparing a client request invocation. Once the request is prepared the invocation builder can be either used to build an Invocation with a generic execution interface:
 Client client = ClientBuilder.newClient();
 WebTarget resourceTarget = client.target("http://examples.jaxrs.com/");

 // Build a HTTP GET request that accepts "text/plain" response type
 // and contains a custom HTTP header entry "Foo: bar".
 Invocation invocation = resourceTarget.request("text/plain")
         .header("Foo", "bar").buildGet();

 // Invoke the request using generic interface
 String response = invocation.invoke(String.class);
 
Alternatively, one of the inherited synchronous invocation methods can be used to invoke the prepared request and return the server response in a single step, e.g.:
 Client client = ClientBuilder.newClient();
 WebTarget resourceTarget = client.target("http://examples.jaxrs.com/");

 // Build and invoke the get request in a single step
 String response = resourceTarget.request("text/plain")
         .header("Foo", "bar").get(String.class);
 
Once the request is fully prepared for invoking, switching to an asynchronous invocation mode is possible by calling the async() method on the builder, e.g.:
 Client client = ClientBuilder.newClient();
 WebTarget resourceTarget = client.target("http://examples.jaxrs.com/");

 // Build and invoke the get request asynchronously in a single step
 Future<String> response = resourceTarget.request("text/plain")
         .header("Foo", "bar").async().get(String.class);