Java Reference
In-Depth Information
a method with @GET . If you want to create a method for updating or inserting an object or data, designate the method
as @POST . If you are creating a method for inserting new objects only, then designate it with @PUT . Finally, if you are
creating a method for removing objects, then designate it with @DELETE .
REST services can become fairly complex if they constitute many different methods and paths. Entire
applications exist based upon REST services, where all Create, Retrieve, Update, Delete (CRUD) manipulations are
invoked via web service calls. This example provides only the foundation for developing with JAX-RS, but it should be
enough to get you started using the API.
Constructing Meaningful URIs
To use a web service, a client must make a call to a URI that will, in turn, invoke the service. Therefore, URIs map to
resource methods, which in turn invoke web service content production or consummation. The URI of a web service
makes a resource method accessible to a web URI. Therefore, it is important to ensure that the URL makes logical
sense with regard to the data that the web resource is consuming or producing. The @Path annotation is used to
indicate the URI that should correspond to the service. The full URI includes the host name, port number, application
name, and REST servlet name, followed by the path designated with the @Path annotation. The following example
demonstrates a simple REST service implementation named SimpleRest .
// Set the PATH to http://host:port/application/rest/simplerest/
public class SimpleRest {
private String message = "Hello from a simple REST Service";
private String htmlMessage = "<p><b>" + message + "</b></p>";
// Produces plain text message
public String getPlainMessage() {
return message;
// Produces plain text message
public String getHTMLMessage() {
return htmlMessage;
Search WWH ::

Custom Search