Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

JAX-RS: Developing RESTful Web Services in Java

Learn how the JAX-RS API and annotations enable you to develop REST-based web services in Java.


advertisement
he simplicity of REpresentational State Transfer (REST), an architectural style for accessing information on the web, has made it a popular way for developers to access services. In the REST architectural style, information on the server side is considered a resource, which developers can access in a uniform way using web URIs (Uniform Resource Identifiers) and HTTP. Because REST uses HTTP as the communication protocol, the REST style is constrained to a stateless client/server architecture.

RESTful web services (i.e., web services that are created and accessed using REST principles) use HTTP protocol methods for the operations they perform (see Table 1 below). For example, a developer can map the HTTP methods POST, GET, PUT, and DELETE to create, read, update and delete (CRUD) operations.

Table 1. HTTP Protocol Methods and the Operations They Perform



For Java developers, JAX-RS (JSR 311) provides an API for creating RESTful web services in Java. Part of the Java EE 6 platform, JAX-RS fully supports REST principles. This article drills down into JAX-RS, exploring its classes and annotations, before demonstrating how to build a simple RESTful web service using JAX-RS.

JAX-RS and the Jersey Project

The JAX-RS API uses annotations to simplify the development of RESTful web services. Annotations, along with the classes and interfaces provided by JAX-RS API, allow you to expose simple POJOs as web resources. Because of its heavy reliance on annotations, JAX-RS requires Java 5 and above.

As with any other Java web application, you bundle JAX-RS applications as a WAR file and deploy them on a container that supports Servlets. You use the Servlets provided by the container to route the requests to the appropriate web resource. A goal of JAX-RS is to enable the portability to deploy web resources across different types of web containers.

Sun offers a reference implementation for JAX-RS code-named Jersey. Jersey uses a HTTP web server called Grizzly, and the Servlet Grizzly Servlet (com.sun.jersey.spi.container.servlet.ServletContainer) handles the requests to Grizzly. You can develop production-quality JAX-RS applications today using Jersey, which implements all the APIs and provides all the necessary annotations for creating RESTful web services in Java quickly and easily. Beyond the set of annotations and features defined by JAX-RS, Jersey provides additional features through its own APIs, such as the Jersey Client API.

You download Jersey separately or acquire it as a bundle with NetBeans 6.5 and GlassFish V3 Prelude.

Developing RESTful Web Services Using JAX-RS

The classes and interfaces you use for creating RESTful web services with JAX-RS are available in the following packages:
  • javax.ws.rs
  • javax.ws.rs.core
  • javax.ws.rs.ext



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap