With each passing year, Java framework scene becomes more and more densely populated. Similar to JavaScript, everyone thinks they know what a good framework should feature and look. Even my grandmother is now using a framework I never heard off or probably won’t ever use. Joking aside, the market is saturated with bloated frameworks that can do almost everything, but for what price?
 
This article is intended to show you currently best available Java RESTful Micro Frameworks. I will try to review only (almost) lightweight products altogether skipping everything that looks bloated and over-featured. At the same time, I want them stable and mature, offering simple, light-weight “getting things done” features. I will break this rule only once covering Play Framework, but more about this topic later.
 
Which Java RESTful Micro Framework will you use in your next project will depend solely on your current needs. To make your life easier, I will list most prominent framework features. Hopefully, this will save some of your time.
 
 

Note: If this tutorial was helpful, need further clarification, something is not working or do you have a request for another Ionic post? Furthermore, if you don't like something about this blog, if something is bugging you, don't like how I'm doing stuff here, again leave me a comment below. I'm here to help you, I expect the same from you. Feel free to comment below, subscribe to my blog, mail me to dragan.gaic@gmail.com, or follow and mention me on twitter (@gajotres). Thanks and have a nice day!

PS. If you want my help, if possible (even if it takes you some time to do that), create a working example I can play with. Use Plunker for AngularJS based questions or jsFiddle for jQuery/jQuery Mobile based questions.


 

Table of Contents

 
 

Intro

Before we go any further, take a look at a list of my chosen eight, in alphabetical order:
 
  • Dropwizard
  • Jersey
  • Ninja Web Framework
  • Play Framework
  • RestExpress
  • Restlet
  • Restx
  • Spark Framework
 
Introduction date: 2011
Rating: 4.5/5
 
Dropwizard provides stable, mature Java libraries assembled into a simple, light-weight package providing you with everything that lets you focus on getting things done.
 
Dropwizard walks the line between a library and a framework. It should provide reliable implementations of everything your web application needs and requires. Because of built-in modularity, an application remains small and lean, reducing development and maintenance time and possible burdens.
 
Dropwizard uses existing Jetty HTTP library embedding it directly into your project, this way external application server is not needed. All Dropwizard projects have a main method which manages built-in HTTP server.

Links

 
 
Official Site GitHub Documentation
 
 

Pro

 
  • Quick project building and bootstraping
  • Modularity
  • Incredibly fast (at least according to built-in metrics)
  • Comes with a Jetty for HTTP, Jersey for REST, and Jackson for JSON.
  • Other libraries are also supported, you may or may not use them (like Mustache, Logback, JDBI, Hibernate Validator, Guava, ….).
  • Monitoring support with Metrics
  • Main method which starts the Jetty server makes it easy to debug and maintain
  • Large community support
 

Con

 
  • Dropwizard documentation is a great source of knowledge though I wouldn’t call it excellent. You will need to search and dig through another 3rd party library documentation’s if you require finding something specific related to other libraries.
  • For some reason errors are handled as plain text, which can be problematic if you expect everything treated as a JSON response.
  • Make sure you’re using newer Dropwizard versions; some of the older ones are using deprecated 3rd party libraries. Plus earlier Dropwizzard versions were harder to upgrade.

 

Example

 
package com.example.helloworld;

import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import com.example.helloworld.resources.HelloWorldResource;
import com.example.helloworld.health.TemplateHealthCheck;

public class HelloWorldApplication extends Application<HelloWorldConfiguration> {
    public static void main(String[] args) throws Exception {
        new HelloWorldApplication().run(args);
    }

    @Override
    public String getName() {
        return "hello-world";
    }

    @Override
    public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
        // nothing to do yet
    }

    @Override
    public void run(HelloWorldConfiguration configuration,
                    Environment environment) {
        // nothing to do yet
    }

}
 

Author notes

 
Personally, I don’t want to recommend this framework for larger projects, but if you’re willing to give it a try, you will not be disappointed. If anything because, primarily this framework uses the best modern Java based web application components available, packaged into an easy-to-use framework.
 
Unfortunately what makes it great also makes it problematic. Mixing all those libraries can cause unforeseen problems, that’s why I gave it 1/2 star less than 5 of 5.
 
Introduction date: 2012 (Jersey 2.X)
Rating: 5/5
 
Jersey RESTful framework is open source framework built upon a JAX-RS (JSR 311 & JSR 339) specification. It provides its API that extends existing JAX-RS reference implementation with additional features and utilities to further simplify RESTful service and client development. Though relatively young (compared to other similar frameworks mentioned in this article) it’s production ready environment meant for RESTful service and client development.
 

Links

 
 
Official Site GitHub Documentation
 
 

Pro

 
  • Excellent documentation + working examples.
  • Fast and cutting edge
  • Extremely easy routing
  • Smooth JUnit integration
  • Personally, when working with RESTful services, JAX-RS implementations are better then MVC frameworks. Though, through some point, it supports MVC.
  • Plays nice with other libraries/frameworks (Grizzly, Netty). Which is probably the main reason it can be found bundled with so many other products.
  • Supports true asynchronous connections
  • Don’t like servlet container? You don’t need to use it with Jersey.
  • WADL, XML/JSON support
  • Included with Glassfish
 

Con

 
  • Jersey 2.0+ uses a somewhat messy dependency injection implemetation
  • Though not a bad thing, Jersey 1.X uses an older JAX-RS implementation then Jersey 2.X
  • A large amount of online resources (3rd party) are related to Jersey 1.X making them unsuitable for Jersey 2.X

 

Example

 
package org.glassfish.jersey.examples.helloworld;
 
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
 
@Path("helloworld")
public class HelloWorldResource {
    public static final String CLICHED_MESSAGE = "Hello World!";
 
@GET
@Produces("text/plain")
    public String getHello() {
        return CLICHED_MESSAGE;
    }
}
 

Author notes

 
Jersey (like Play) is a framework of my choice, easily 5/5.
 
Introduction date: 2012
Rating: 3.5/5 (I’m not impressed enough)
 
Ninja Web Framework is a full-stack web framework for Java. Stable, fast, reliable, and super productive.
 
It provides everything you need to develop, test, deploy, and maintain your RESTful web application (Servlets, Guice, JPA, Flyway migrations, Maven, etc.).
 
Just like DropWizzard, Ninja Web Framework is an integrated software stack. You don’t have to setup everything on your own, just generate a new project from using Maven archetype, import it into available IDE and start coding.

Links

 
 
Official Site GitHub Documentation
 
 

Pro

 
  • Fast
  • Quick project building and bootstrapping
  • Modularity
  • XML, HTML, JSON rendering
  • Other libraries are also supported, you may or may not use them (like Guice, Logback, Guava, etc.).
  • Good data persistence support and caching
  • Don’t like servlet container? Use any container you like.
  • Don’t want to use containers at all? Use it in stand-alone mode, as a self-executing jar package bundled with Jetty.
 

Con

 
  • Again, just like with DropWizzard, provided documentation is good but not good enough. It took me some time to get acquainted. Also, this framework relies on so many other libraries that sometimes it can become cumbersome to find needed information.
  • Not that famous, so expect much smaller community. According to some rumors, this framework was built by/for Play users who didn’t like Play 2.X switching mainly to Scala. Please leave a comment below if you think this is not correct.

 

Example

 
package controllers;

public class ApplicationController {       

    public Result index() {

        Person person = new Person();
        person.name = "John Johnson";

        return Results.json().render(person);

    }
}
 

Author notes

 
It sounds like a great framework, but I will leave it on the side until it matures a little bit more.
 
Continue Reading

  • Antonio Garcia

    Hi
    I use this framework in my last work. I pick over other for the benchmark. This is because the use of Jetty.
    I do not use the framework at 100%, the core and JDBI but the documentation is very terse = much StackOverflow.
    JodaTime is included what is interesting.

  • Edgar Espina

    Good article!

    Here is another micro framework: http://jooby.org (I’m the author)

    It runs on top of netty (default), jetty or undertow. It has a scripting programming model but also MVC.

    • Ahmmad Ismail

      I am pretty much considering your framework. However, It will be great if you can provide some video tutorials. Otherwise it is hard to gain confidence to get started for a project on which I will be stick to for next 4/5 years at least.

  • My advice, go to the Ionic official forum. Sort answers by “number of replies”, and you’ll find your answer somewhere on the top. It’s a standard Ionic question.

  • C B Newham

    I don’t know why you claim Spark is not intended for beginners. I’m no expert on restful frameworks (Spark was the first I used) but I found the documentation to be adequate and it does exactly what I want with minimal fuss.

  • Thanks I will check it out

  • Thanks I will check it out, do you mind if I contact you with few questions?

    • Feel free to contact me with any question you might have.

  • Jay Ma

    No RestEasy?

  • Danio

    Great article. Can you explain these two:

    “Most commonly used with AngularJS”
    – isn’t AngularJS alone enough to develop front-end and just call backend without use of Spark framework?

    “Can be used inside a container or without one”
    – you wanna tell it does not have to use Jetty at all.. it is configurable? I did not know that

  • Jonathan Airey

    Dropwizzard -> Dropwizard.

  • Yohanes Pradono

    I am new to Java and am building a simple restful application. I am considering Dropwizard, Jersey, or Play2. still struggling on where i should put my faith on.

    • Ferran Maylinch

      Would recommend Spring Boot or Dropwizard. Not Play, it has too many issues.
      Dropwizard is easy to use. Spring Boot too, and Spring products are always of high quality and well documented.

  • Yohanes Pradono

    Does grails require you to know Groovy? or it can be developed using java only knowledge?