LibraryToggle FramesPrintFeedback

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.

Example 2.1. Simple resource class

package demo.jaxrs.server;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@Path("/customerservice") 1
public class CustomerService
{
  public CustomerService()
  {
  }

  @GET 2
  public Customer getCustomer(@QueryParam("id") String id)
  {
    ...
  }

  ...
}

Two items make the class defined in Example 2.1 a resource class:

1

The @Path annotation specifies the base URI for the resource.

2

The @GET annotation specifies that the method implements the HTTP GET method for the resource.

Comments powered by Disqus