Difficulty: Beginner
Estimated Time: 10 minutes

Java API for RESTful Web Services (JAX-RS) is a Java programming language API specification that provides support in creating web services according to the Representational State Transfer (REST) architectural pattern. By using a stateless protocol and standard operations, REST systems aim for fast performance, reliability, platform-independence and the ability to grow, by re-using components that can be managed and updated without affecting the system as a whole, even while it is running.

Resteasy is a fully certified and portable implementation of JAX-RS, which has a rich set of useful components and can be installed in multiple environments. In this tutorial, we'll use Resteasy to create a simple RESTful Web application and a client to invoke it.

Now, you have had a basic knowledge of creating, deploying and calling a REST API using Resteasy and Wildfly. On the basis of this, you can establish more powerful RESTful APIs and explore more interesting features of Resteasy! For more information about using Resteasy, see: Resteasy Documentation

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Creating Your First JAX-RS Application Using Resteasy

Step 1 of 7

Introduction to Resteasy

Prepare the environment

What we need includes:

  • Java
  • Maven (3.0.4 or higher)
  • Web Container
  • Resteasy

WildFLy is the best choice for web container, in which Resteasy is pre-installed. In this case, we'll use Java 8, Maven 3.5.0 and WildFly 11.0.0 Final as our environment.

The structure of a Resteasy web application project is in correspondence with a maven web project. And it is shown in the editor in the right.

In the pom.xml, some dependencies are already added to support the application.

Define the version of Resteasy used.

<properties>
   <resteasy.version>3.1.4.Final</resteasy.version>
</properties>

Dependencies required by server:

<dependencies>
   <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxrs</artifactId>
      <version>${resteasy.version}</version>
      <scope>provided</scope>
   </dependency>
   <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-servlet-initializer</artifactId>
      <version>${resteasy.version}</version>
      <scope>provided</scope>
   </dependency>
</dependencies>

For the jars above have been included in Wildfly, it is a wise decision to set the scope as "provided" to minimize the war file.

Dependencies required by client:

<dependencies>
   <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-client</artifactId>
      <version>${resteasy.version}</version>
      <scope>test</scope>
   </dependency>
   <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jackson-provider</artifactId>
      <version>${resteasy.version}</version>
      <scope>test</scope>
   </dependency>
</dependencies>

Here we use scope "test" to support the execution maven exec plugin.

Resteasy-jackson-provider is used to support the transformation of application/json media type. Resteasy also has many other kinds of providers, see resteasy providers

Now we have the basic environment to working on.