Javatpoint Logo
Javatpoint Logo

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.

AnnotationDescription
PathIt identifies the URI path. It can be specified on class or method.
PathParamrepresents the parameter of the URI path.
GETspecifies method responds to GET request.
POSTspecifies method responds to POST request.
PUTspecifies method responds to PUT request.
HEADspecifies method responds to HEAD request.
DELETEspecifies method responds to DELETE request.
OPTIONSspecifies method responds to OPTIONS request.
FormParamrepresents the parameter of the form.
QueryParamrepresents the parameter of the query string of an URL.
HeaderParamrepresents the parameter of the header.
CookieParamrepresents the parameter of the cookie.
Producesdefines 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.
ConsumesIt 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 : javatpoint 
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




Please Share

facebook twitter google plus pinterest tumbler

Learn Latest Tutorials