JAX-RS: Java API for RESTful web services

JAX-RS is the Java API for developing RESTful web services.

It is a POJO-based, HTTP centric API. The API provides a set of annotations and associated classes/interfaces that may be used with POJOs in order to expose them as Web resources.

Some commonly used terms:

  • Resource Class: A Java class that uses JAX-RS annotations to implement a corresponding Web resource.
  • Root Resource Class: A resource class annotated with @Path. Root resource classes provide the roots of the resource class tree and provide access to sub-resources.
  • Request Method Designator: A runtime annotation annotated with @HttpMethod. Used to identify the HTTP request method to be handled by a resource method.
  • Resource Method: A method of a resource class annotated with a request method designator that is used to handle requests on the corresponding resource.
  • Sub-resource Locator: A method of a resource class that is used to locate sub-resources of the corresponding resource.
  • Sub-resource Method: A method of a resource class that is used to handle requests on a sub-resource of the corresponding resource. It is different from a sub-resource locator in that the method is annotated with a request method designator.

Hello World - Lets Start It

The following is a simple Hello World web resource which is developed using the JAX-RS annotations:

       @Path("/helloworld")

        public class HelloWorldResource {

                @GET

                 public String sayHello() {

                          return "Hello World, welcome to the REST land!!!";

                }

        }

In this sample, the HelloWorldResource class is annotated with the @Path annotation, and is the root resource class as defined above. The method sayHello is annotated with the request method designator @GET and is the resource method. If we assume that the application is deployed on a container and that its base URI is http://someserver/restdemo, a HTTP GET request http://someserver/restdemo/helloworld shall invoke the sayHello resource method defined in the HelloWorldResource above.

Useful links

  1. JAX-RS 1.0 spec.
  2. JSR-311 API javadocs.
  3. Overview of JAX-RS features.
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Naresh worked at Sun Microsystems for two years. During these two years he had worked on the Project Metro and Project Jersey.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today