Marc Rufer 06 Jun 2015 RESTful Dropwizard Java development
Once at work a friend asked me, if I know dropwizard. I have never heard about it before, so I decided to have a look at it and try it out. Dropwizard is a Java framework for development of high-performance RESTful web services.
To get in touch with dropwizard I went through the getting started guide. I created a new repository at GitHub, where I checked in the source code I wrote while going through the getting started guide.
The Dropwizard framework uses the Jetty HTTP library for embedding a HTTP server directly into the project. Dropwizard applications are usually delivered as a FAT-jar, which contain a main method to spin up the embedded HTTP server. The RESTful services developed with Dropwizard are based on jersey and for JSON serialization and deserialization the framework uses the Jackson JSON library. Dropwizard applications support operation tools for metrics, thread dumps, ping and health checks out of the box and are capable of doing 30’000-50’000 requests per second.
The setup of a Dropwizard project was quite easy. Such an application consists out of the following parts:
Configuration class In the configuration class the environment specific parameters are defined. In this case the template message template and the default name. The values of these parameters are defined in a YAML-file (example.yml).
Configuration file (YAML) This file contains the values of the parameters defined in the configuration class.
Application class Similar to spring boot you have to define an application class, which has to extend the Application class from Dropwizard parametrized with the configuration class. It contains the main method, which runs the HTTP server. In the run method you have to define and register the health checks and resources (Examples of health check and resource classes can be found below).
Representation class This class is optional, but was added to wrap the REST responses into a common top level object, which always contains an id and a data object.
The resource class describes the REST resource and is associated with an URI template. The
getExample method defines a GET endpoint, which serves a response wrapper object containing some data in the content JSON object. The @Timed annotation on the
getExample method causes that the duration and rate of its invocations is automatically recorded as a Metrics Timer.
There is a possibility to create custom health check classes, which expose health check data to the operation tools.
It’s recommended to build Dropwizard application as FAT-jars. How to do that using Maven is described in the getting started.
Throughout this short dive into Dropwizard I noticed that the framework is easy to use and works very well. The getting started guide is well illustrated and contains good descriptions of every part of the application. Especially impressive was the out of the box operational tools (metrics, thread dump, ping and health check). I didn’t do some load test, so I can’t place any statement about performance, but as written in the documentation Dropwizard applications should be able to handle 30’000-50’000 requests per second. I think the framework is a good option for implementing RESTful web service i.e. microservices. As well for creating demonstrations or PoC it would be a straight forward approach using Dropwizard.