RESTEasy Tutorial for Beginners

RESTEasy is JBOSS-provided implementation of JAX-RS specification (the latest version implements Jakarta-RS) for building REST APIs. RESTEasy is a portable implementation of these specifications which can run in any Servlet container. A tighter integration with the WildFly application server makes the user experience nicer.

1. Bootstrapping a RESTEasy Application

The bootstrapping of a RESTEasy application depends on the environment we are running it in. Let us check its configuration for a WildFly as well as a 3rd-party servlet container, both.

1.1. In WildFly

In WildFly, RESTEasy and the Jakarta RESTful Web Services API are automatically loaded. So if we are already using the Jakarta RESTful Web Services annotations, we do not need to do much to make this work.

If any module is not loaded by default, then we can import using the jboss-deployment-structure.xml. In following example, we are additionally importing the resteasy-jackson2-provider module.

            <module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>

By default, WildFly automatically scans the application classes for the Jakarta-RS annotations and configures them. The easiest way to start is by creating a class that extends and is annotated with @ApplicationPath annotation. The UserService class provides all REST endpoints using the @Path annotation. In this case, a web.xml file is not required.

public class RestEasyApplication extends Application
    private Set<Class> classes = new HashSet<Class>();

    public RestEasyApplication() {

    public Set<Class<?>> getClasses() {
        return super.getClasses();

    If the above class does not have the @ApplicationPath annotation then we must define the servlet-mapping element in the web.xml file.


    1.2. In Other Servlet Containers

    Start with including the latest version of RESTEasy modules from the Maven repository.


    In Servlet 3.0 containers and later, we will need to include the resteasy-servlet-initializer dependency, which includes an implementation of the ServletContainerInitializer interface for containers to use in initializing the RESTEasy application. It will automatically scan the application classes for the resources and providers, and programmatic registration of a servlet.


    You will need to include a similar servlet-mapping in older servlet containers as mentioned in the previous section.

    2. REST Controller

    We can now create the REST APIs as we will in any other application using the Jakarta-RS annotations.

    import jakarta.xml.bind.annotation.*;
    public class UserService {
      public Users getAllUsers() {
        Users users = new Users();
        return users;
      public User getUserById(@PathParam("id") int id) {
        if (id > UserCache.getUsers().size()) {
          //report error
        return UserCache.getUsers().get(id - 1);

    3. Demo

    When we deploy the above-built application in Tomcat 10 and hit the URL: /resteasy-examples/rws/user-management/users/

    This endpoint should return all the users in the system, and we shall receive an XML response.

    4. Conclusion

    In this RESTEasy tutorial, we learned to bootstrap REST APIs using RESTEasy. We learned to create and deploy the API code in WildFly server as well as other Servlet containers such as Tomcat.

    Happy Learning !!

    Sourcecode on Github


    Notify of
    Most Voted
    Newest Oldest
    Inline Feedbacks
    View all comments

    About Us

    HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

    It also shares the best practices, algorithms & solutions and frequently asked interview questions.