Java Reference
In-Depth Information
Using the @POST annotation
The @javax.ws.rs.POST annotation is a marker annotation and signals that the web
service is invoked using the HTTP POST method. The following code snippet is all there
is to the POST annotation:
@Target(value = {ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
@HttpMethod(value = "POST")
public @interface POST {}
An HTTP POST method is used for pushing data up to the server—for example, adding
a picture of an item to ActionBazaar. The content of the message contains the new record
or an annotation of an existing record on the server. Note that the operation doesn't neces-
sarily result in a new resource that can be identified by a URI. In a given POST request,
multiple attachments can be uploaded if the message is encoded as a multipart mime mes-
sage; see, for example, the @Consumes annotation.
Using the @DELETE annotation
The @javax.ws.rs.DELETE annotation is a marker annotation that signals that the
web service is invoked using the HTTP DELETE method. The resource identified by the
URI should be deleted with any subsequent operations using the same URI but doing noth-
ing—the resource has already been deleted:
@Target(value = {ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
@HttpMethod(value = "DELETE")
public @interface DELETE {}
Using the @Path annotation
The @javax.ws.rs.Path annotation can be placed on both a class and a method.
When it's placed on a class, it designates the class as a JAX-RS service. A class that's ex-
posing RESTful web services must have this annotation. If the annotation is placed on a
method, the method is exposed as a RESTful web service.
The value pass into the @Path annotation is the relative URI for the service. The URI
provided in a method annotation, as you saw previously, is combined with the URI on the
Search WWH ::




Custom Search