Java Reference
In-Depth Information
8
Spring REST doesn't follow the JAX-RS specification. Apache CXF was designed for JAX-WS, but the latest
version has JAX-RS support. Apache Wink is another JAX-RS 1.x implementation.
9
If I had to bet, I'd go with Restlet. Most of the good REST people I know really like it.
Therefore, I'm basing this chapter on the JAX-RS specification, even though it's not ne-
cessarily the most popular alternative. When the alternative is not blindingly obvious, the
spec usually wins.
[
10
]
10
Except when it doesn't. See, for example, JDO, which is still part of Java EE.
The application in this section exposes a POGO called
Person
as a JAX-RS 2.0 resource.
The application supports GET, POST, PUT, and DELETE operations and (eventually) sup-
ports hypermedia links.
The infrastructure for the project includes the POJO, Spock tests, and a DAO implementa-
tion based on an H2 database. While the implementations are interesting, they are ancillary
to the real goal of discussing RESTful services and how Groovy can simplify their devel-
opment. Therefore they will not be presented in detail in this chapter. As usual, the com-
plete classes, including Gradle build files and tests, can be found in the topic source code
repository.
As a brief summary, the
Person
class is shown in the next listing.
Listing 9.1. A
Person
POGO, used in the RESTful web service
class Person {
Long id
String first
String last
String toString() {
"$first $last"
}
}
The DAO interface for the
Person
objects includes finder methods, as well as methods to
create, update, and delete a
Person
. It's shown in the following listing.