Java Reference
In-Depth Information
@PUT @Path("{id}")
@Consumes([MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML])
@Produces([MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML])
Person update(Person person) {
dao.update(person)
person
}
@DELETE @Path("{id}")
Response remove(@PathParam("id") long id) {
dao.delete(id);
Response.noContent().build()
}
}
Most discussions of JAX-RS end at this point, with a working, URL-driven database. True
REST is more flexible than that, however. A RESTful service is supposed to act like the
web, in that it presents a single URL to the client, which accesses it and receives additional
links in return. This is known as HATEOAS, or simply hypermedia.
Lessons learned (JAX-RS with Groovy)
1. Groovy doesn't significantly change JAX-RS.
2. The real Groovy simplifications are in the POGO and DAO classes. The resource
implementation is essentially the same in both languages.
Hypermedia links are exposed to clients, which consume them. JAX-RS 1.x doesn't in-
clude a client-side API. Version 2.0 does, and there's a convenient project in the Groovy
ecosystem known as HttpBuilder for performing HTTP requests. Both are the subjects of
the next section.
9.4. RESTful Clients
Accessing a RESTful web service involves creating an HTTP request of the proper type
and adding any necessary information to the body. One of the biggest changes in JAX-RS
when moving from version 1 to version 2 is the addition of a standard client API. The API
includes Client and WebTarget classes, which are used as follows:
 
Search WWH ::




Custom Search