/jetrs

A fast and lightweight implementation of Java's JAX-RS 2.1 server specification built to run in a servlet container.

Primary LanguageJavaMIT LicenseMIT

JetRS

NOTE: This README it outdated!

Build Status Coverage Status Javadocs Released Version Snapshot Version

Introduction

JetRS is an implementation of the JAX-RS v2.0 Specification that runs in a Servlet Container. This project was inspired with the goal to create a better, simpler, easier to use, reliable, and debugable JAX-RS implementation using the CohesionFirst approach.

Getting Started

Prerequisites

  • Java 8 - The minimum required JDK version.
  • Maven - The dependency management system.
  • Servlet Container - A Servlet Container is needed to provide the HTTP service functionality. We recommend Jetty as the ideal starting point for any project.

Example

  1. Add the org.jetrs:server dependency to the POM.

    <dependency>
      <groupId>org.jetrs</groupId>
      <artifactId>server</artifactId>
      <version>2.1.0-alpha-3</version>
    </dependency>
  2. Optionally, you can add the dependency for the MessageBodyReader and MessageBodyWriter provider to integrate the JSONx RS module.

    <dependency>
      <groupId>org.jsonx</groupId>
      <artifactId>jaxrs</artifactId>
      <version>0.3.2</version>
    </dependency>
  3. Create a javax.ws.rs.core.Application.

    @javax.ws.rs.ApplicationPath("/*")
    public class Application extends javax.ws.rs.core.Application {
      @Override
      public java.util.Set<Object> getSingletons() {
        java.util.Set<Object> singletons = new java.util.HashSet<Object>();
        singletons.add(new org.jsonx.rs.JxObjectProvider()); // Optional Provider to parse and marshal JSON messages to Java beans.
        return singletons;
      }
    }
  4. Extend org.jetrs.server.DefaultRESTServlet, pointing to Application.

    @WebServlet(initParams={@WebInitParam(name="javax.ws.rs.Application", value="Application")})
    public class RESTServlet extends org.jetrs.server.DefaultRESTServlet {
    }
  5. Deploy the servlet to a Servlet Container. For an easy embedded servlet container solution, see here for a solution based on Jetty. In the arguments to new Server(8080, ...) add RESTServlet.class as such:

    new Server(8080, RESTServlet.class);

    This will automatically add RESTServlet to the application.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

This project is licensed under the MIT License - see the LICENSE.txt file for details.