RESTful Web services implemented using JAX-RS APIs provide responses as representations of a resource implemented by Java classes. A resource class is a class that uses JAX-RS annotations to implement a resource. For most RESTful Web services, there is a collection of resources that need to be accessed. The resource class' annotations provide information such as the URI of the resources and which HTTP verb each operation handles.
The JAX-RS APIs allow you to create two basic types of resources:
A root resource class is the entry point to a service's resource tree. It is decorated with the
@Path
annotation to define the base URI for the resources in the service.Sub-resources are accessed through the root resource. They are implemented by methods that are decorated with the
@Path
annotation. A sub-resource's@Path
annotation defines a URI relative to the base URI of a root resource.
Example 2.1 shows a simple resource class.
Two items make the class defined in Example 2.1 a resource class: