RESTful Web Services - Java (JAX-RS)

RESTful Web Services - Java (JAX-RS)

JAX-RS stands for JAVA API for RESTful Web Services. JAX-RS is a JAVA-based programming language API and specification that provides support for built RESTful web services. Its version 2.0 was released on May 24, 2013. JAX-RS makes use of the annotations available in Java SE 5 to make it easier for developers to create and deploy JAVA-based web services. It also supports creating clients for RESTful web services.

Characteristics

Following are the most commonly used annotations for mapping a resource as a web service resource.

Sr.No. Abstract and description

one

@Track

The relative path of the class/method of the resource.

2

@RECEIVE

HTTP Get request, used to get a resource.

3

@PUT

The HTTP PUT request used to create the resource.

4

@MESSAGE

HTTP POST request used to create/update a resource.

five

@DELETE

The HTTP DELETE request used to delete the resource.

6

@HEAD

HTTP HEAD request, used to get the accessibility status of a method.

7

@Produces

Sets the HTTP response generated by the web service. For example, APPLICATION/XML, TEXT/HTML, APPLICATION/JSON, etc.

8

@Consumes

Sets the HTTP request type. For example, application/x-www-formurlen is coded to accept form data in an HTTP body during a POST request.

nine

@PathParam

Associates a parameter passed to a method with a value in the path.

10

@QueryParam

Associates the parameter passed to the method with a query parameter in the path.

eleven

@MatrixParam

Associates the parameter passed to the method with the HTTP matrix parameter in the path.

12

@HeaderParam

Associates a parameter passed to a method with an HTTP header.

13

@CookieParam

Associates a parameter passed to a method with a cookie.

fourteen

@FormParam

Associates the parameter passed to the method with the value of the form.

15

@Default value

Assigns a default value to a parameter passed to a method.

16

@Context

Resource context. For example, HTTPRequest as context.

one

@Track

The relative path of the class/method of the resource.

2

@RECEIVE

HTTP Get request, used to get a resource.

3

@PUT

The HTTP PUT request used to create the resource.

4

@MESSAGE

HTTP POST request used to create/update a resource.

five

@DELETE

The HTTP DELETE request used to delete the resource.

6

@HEAD

HTTP HEAD request, used to get the accessibility status of a method.

7

@Produces

Sets the HTTP response generated by the web service. For example, APPLICATION/XML, TEXT/HTML, APPLICATION/JSON, etc.

8

@Consumes

Sets the HTTP request type. For example, application/x-www-formurlen is coded to accept form data in an HTTP body during a POST request.

nine

@PathParam

Associates a parameter passed to a method with a value in the path.

10

@QueryParam

Associates the parameter passed to the method with a query parameter in the path.

eleven

@MatrixParam

Associates the parameter passed to the method with the HTTP matrix parameter in the path.

12

@HeaderParam

Associates a parameter passed to a method with an HTTP header.

13

@CookieParam

Associates a parameter passed to a method with a cookie.

fourteen

@FormParam

Associates the parameter passed to the method with the value of the form.

15

@Default value

Assigns a default value to a parameter passed to a method.

16

@Context

Resource context. For example, HTTPRequest as context.

Note. We used Jersey, Oracle's JAX-RS 2.0 reference implementation, in the RESTful Web Services - First Application and RESTful Web Services - Methods chapters .