Creating JAX-RS web service using RESTEasy Example


RESTEasy is a JBoss Project and an implementation of JAX-RS specification.  It’s simplified nature made a huge noise on the backend developers community and to this day, one of the widely used JAX-Rs implementation. How easy is it? Let’s find out.

What are we doing?

We are doing a step by step guide on how to create a RESTEasy service.

1. Create a webapp using Maven and plug in the RESTEasy dependency.

We need to add the dependency first on your web app.


<project xmlns="" xmlns:xsi=""
	<name>resteasy-sample Maven Webapp</name>
		  <id>JBoss repository</id>

2. Additional configuration on the webapp

We also need to put additional configurations on the web.xml file as we need the app to recognize our service.


 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

  <display-name>Archetype Created Web Application</display-name>
  <!-- Auto scan REST service -->
	<!-- this need same with resteasy servlet url-pattern -->

3. Create the service

The fun part! Let’s create the service!

package com.javacodegeeks.areyes;
public class CustomerRestService {
	public Response printMessage(@PathParam("param") String msg) {
		String result = "Restful Return! : " + msg;
		return Response.status(200).entity(result).build();

As it can be seen above, there’s a bunch of Annotations that we used. These annotations are crucial as it allows the JVM to categorize this source code to have a configuration injected to it. The following annotations are described below:

  • @Path – The endpoint url path.
  • @Get – This means that the method is called using the GET http method.
  • @PathParam – Query parameters passed via the URL.

What I really liked about RESTEasy is that it lives up to it’s name. It’s just plain simple. Just annotate and your service is ready to go!

4. Let’s test it

Deploy your app to a J2EE container and go to:

http://localhost:8080/resteasy-sample/rservice/customer/printmessage/<your message>

Figure 1: RESTeasy sample output

Download the Eclipse Project

This was an example of creating a JAX-RS compliant web service using RESTEasy

You can download the full source code of this example here:

Alvin Reyes

Alvin has an Information Technology Degree from Mapua Institute of Technology. During his studies, he was already heavily involved in a number of small to large projects where he primarily contributes by doing programming, analysis design. After graduating, he continued to do side projects on Mobile, Desktop and Web Applications.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
sobia aijaz
sobia aijaz
4 years ago

i deployed ur war, and got this error

Message /resteasy-sample/rservice/customer/printmessage/message

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/8.5.42

any ideas?

Back to top button