Java Reference
In-Depth Information
In this case I'm running the Grizzly test server on port 1234, and for this demo the data is
in JSON form. The test for the GET method produces the following:
def response = client.get(path: 'people')
response.status == 200
response.contentType == 'application/json'
response.data.size() == 5
The
RESTClient
provides a
get
method that takes a
path
parameter. The response
comes back with special properties for (most of) the typical headers. Other headers can
be retrieved either by requesting the
allHeaders
property or by calling
get-Head-
er("...")
with the required header. Any returned entity in the body of the response is
in the
data
property.
DELETE requests.
14
Again, sorry. At some point (and that may already have happened), when I say, “No pun intended,” you're simply
not going to believe me.
Lessons learned (REST clients)
1. JAX-RS 2.0 includes classes for building REST clients.
[
15
]
15
The JAX-RS client classes are very easy to use, too, which is unfortunate when you're trying to show
how cool Groovy is, but helpful for users. Oh well.
2. The Groovy project HttpBuilder wraps the Apache HttpClient project and makes it
easier to use.
Both the
RESTClient
and the JAX-RS 2.0 client are used in the test cases in the hyper-
media section, which is as good a segue as any to finally discuss HATEOAS in Java.
9.5. Hypermedia
A series of resource URLs is not a RESTful web service. At best, it's a URL-driven data-
base. Yet applications like that, which claim to be RESTful services, are all over the web.