Home » RESTful JAX-RS Annotations Example

RESTful JAX-RS Annotations Example

by Online Tutorials Library

RESTful JAX-RS Annotations Example

JAX-RS API provides following annotations to develop RESTful applications in java. We are using jersey implementation for developing JAX-RS examples.


Click me to download jersey jar files.


JAX-RS Annotations

The javax.ws.rs package contains JAX-RS annotations.

Annotation Description
Path It identifies the URI path. It can be specified on class or method.
PathParam represents the parameter of the URI path.
GET specifies method responds to GET request.
POST specifies method responds to POST request.
PUT specifies method responds to PUT request.
HEAD specifies method responds to HEAD request.
DELETE specifies method responds to DELETE request.
OPTIONS specifies method responds to OPTIONS request.
FormParam represents the parameter of the form.
QueryParam represents the parameter of the query string of an URL.
HeaderParam represents the parameter of the header.
CookieParam represents the parameter of the cookie.
Produces defines media type for the response such as XML, PLAIN, JSON etc. It defines the media type that the methods of a resource class or MessageBodyWriter can produce.
Consumes It defines the media type that the methods of a resource class or MessageBodyReader can produce.

JAX-RS @Path, @GET and @PathParam Annotations

File: HelloService.java

File: web.xml

File: index.html

Now run this application on server, you will see the following output:

Output:

Jersey say : tutoraspire  

Click me to download this example


JAX-RS Multiple @PathParam Annotation

File: HelloService.java

File: web.xml

It is same as above example.

File: index.html

Now run this application on server, you will see the following output:

Output:

getDate is called, year/month/day : 2014/12/5 

Click me to download this example


JAX-RS @FormParam and @POST Annotation

File: HelloService.java

File: web.xml

It is same as above example.

File: index.html

Now run this application on server, you will see the following output:

Output:

jax rs form param example
jax rs annotation form param example
Click me to download this example


You may also like