iif ( response . getStatus () != 204 )
new RuntimeException ( "Failed to update" );
response . close ();
System . out . println ( "**** After Update ***" );
customer = client . target ( location ). request (). get ( String . class );
System . out . println ( customer );
client . close ();
The Client API is a fluent API in that it tries to look like a domain-specific language (DSL).
The Client API has a lot of method chaining, so writing client code can be as simple and
compact as possible. In the preceding example, we first build and execute a POST request to
create a customer. We then extract the URI of the created customer from a Response object
to execute a GET request on the URI. After this, we update the customer with a new XML
representation by invoking a PUT request. The example only uses Strings , but we'll see in
Chapter 6 that JAX-RS also has content handlers you can use to marshal your Java objects
automatically to and from XML and other message formats.
In this chapter, we discussed how to implement a simple customer database as a JAX-RS ser-
vice. You can test-drive this code by flipping to Chapter 18 . It will walk you through in-
stalling JBoss RESTEasy, implementing JAX-RS, and running the examples in this chapter
within a servlet container.