RESTful Web Services - Java (JAX-RS)


Advertisements


JAX-RS stands for JAVA API for RESTful Web Services. JAX-RS is a JAVA based programming language API and specification to provide support for created RESTful Web Services. Its 2.0 version was released on the 24th May 2013. JAX-RS uses annotations available from Java SE 5 to simplify the development of JAVA based web services creation and deployment. It also provides supports for creating clients for RESTful Web Services.

Specifications

Following are the most commonly used annotations to map a resource as a web service resource.

Sr.No. Annotation & Description

1

@Path

Relative path of the resource class/method.

2

@GET

HTTP Get request, used to fetch resource.

3

@PUT

HTTP PUT request, used to create resource.

4

@POST

HTTP POST request, used to create/update resource.

5

@DELETE

HTTP DELETE request, used to delete resource.

6

@HEAD

HTTP HEAD request, used to get status of method availability.

7

@Produces

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

8

@Consumes

States the HTTP Request type. For example, application/x-www-formurlencoded to accept form data in HTTP body during POST request.

9

@PathParam

Binds the parameter passed to the method to a value in path.

10

@QueryParam

Binds the parameter passed to method to a query parameter in the path.

11

@MatrixParam

Binds the parameter passed to the method to a HTTP matrix parameter in path.

12

@HeaderParam

Binds the parameter passed to the method to a HTTP header.

13

@CookieParam

Binds the parameter passed to the method to a Cookie.

14

@FormParam

Binds the parameter passed to the method to a form value.

15

@DefaultValue

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

16

@Context

Context of the resource. For example, HTTPRequest as a context.

Note − We have used Jersey, a reference implementation of JAX-RS 2.0 by Oracle, in the RESTful Web Services - First Application and RESTful Web Services - Methods chapters.



Advertisements
E-Books Store