Creating and deploying RESTful Web Services with JAX-RS
In the Basics of RESTful web services post I provided you in theory with how does REST APIs work. Starting from this tutorial, we’ll go through that in practice. First, we’ll create and deploy a simple REST web service using the Java API for RESTful web Services, JAX-RS. Then in the following tutorials we’ll see how to consume a REST web service with JAX-RS, and more.
This tutorial post is associated to a youtube video so we can go better through practice and put theories aside for a while. Still, we’ll have to define some points before actually starting.
JAX-RS 2.0 Specification
The Java API for RESTful web services (JAX-RS) is “a set of portable APIs for developing, exposing and accessing web applications designed and implemented in compliance with the principles of REST architectural style“. It aims to make development of RESTful web services in Java simple and intuitive. The initial impetus for the API came from the observation that existing Java Web APIs were generally either:
- Very low level, leaving the developer to do a lot of repetitive and error-prone work such as URI parsing and content negotiation, or
- High level and proscriptive, making it easy to build services that conform to a particular pattern but lacking the necessary flexibility to tackle more general problems.
A Java Specification Request (JSR 311) was filed with the Java Community Process (JCP) in January 2007 and approved unanimously in February. Since then multiple implementations of the API were adopted. The latest version JAX-RS 2.0 [JSR 339], was released as part of the Java EE 7 platform.
JAX-RS uses Java annotations to reduce the need for standard base classes, implementing required interfaces, and out-of-band configuration files. Annotations are used to route client requests to matching Java class methods and declaratively map request data to the parameters of those methods. These are also used to provide static metadata to create responses.
As JAX-RS is a specification, we’ll need to have its implementation to build and manage restfull webservices. Some of the popular JAX-RS implementations available today are:
• Jersey
• RESTEasy
• Apache CXF
• Restlet
We’ll use the RESTEasy implementation of JAX-RS through our tutorials series.
Follow up with this video where we’ll create a simple REST webservice and deploy it to Wildfly app-server to test it. We’ll go through configuring JAX-RS, annotating a Java class to expose it as a REST resource, and test out the cases where our webservice expose methods with/without parameters
Recent Comments