7.18. JAX-RS

JAX-RS (Java API for REST Web Services) is a standard for implementing REST based services in Java. The major part of the standard is a mapping of REST service resources to Java classes, which is accompanied by a definition of implementation packaging.

In the mapping, annotations are used to denote classes that represent resources. Further annotations specify path templates for those resources. Method annotations specify handlers for requests. Resource classes are instantiated for individual requests.

The mapping also defines provider classes, responsible for custom marshalling and custom context. Standard provider classes handle marshalling of common content such as strings, maps, XML.

Figure 7.38. Service Example

@Path ("example")
public class ExampleResource {
  @GET
  @Path ("{key}")
  @Produces ("application/value+xml")
  public KeyValueType getKeyValue (@PathParam ("key") String key) {...}

  @DELETE
  @Path ("{key}")
  public void deleteKeyValue (@PathParam ("key") String key) {...}
}