Rapid REST API Development With Dropwizard

DZone 's Guide to

Rapid REST API Development With Dropwizard

Dropwizard is a popular framework that can get us up to speed developing REST services in little to no time. Check out this great post on how to get started.

· Java Zone ·
Free Resource

As a developer, you all know about REST APIs. There are tons of frameworks available in Java to develop RESTful web services. Jersey, RESTeasy, and Spring are some of the popular frameworks available in the market. Have you ever felt your REST API development process was set up in a straight forward way? Probably not!

But one framework which I evaluated recently has mostly positive aspects, and it allowed me to focus on my business problems instead of the plumbing work to prepare the infrastructure. This is none other than “Dropwizard

This tiny framework came very late in the market when compared to most of the other frameworks and attract the developer’s attention is a shorter time. In 2012 it was mentioned in the Thoughtworks technology radar as “TRIAL”. It jumped to “ADAPT” with-in 2 years gap (Refer https://www.thoughtworks.com/radar/languages-and-frameworks/dropwizard)

Why I like Dropwizard

  • Easy development setup
  • In-built metrics infrastructure
  • Health check
  • Embedded HTTP Server

Beauty Of Dropwizard

Dropwizard is like a developer's BOX. It contains all the good parts which are required for easy development. For example, it contains the following well known APIs and frameworks to ease our development:

  • REST API – Jersey
  • Logging – Logback
  • Deployment – Jetty
  • Metrics – Metrics library
  • Health check – In built
  • Collection Util – Google Guava
  • JSON Parsing – Jackson library
  • and many more…

Ok we have seen some of the good parts of Dropwizard framework. In the next section we will quickly see the code for developing a REST API. First we have to create a Maven based project and add the following changes in your pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">


                  <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                  <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

  <!-- list dependencies -->




public class BookResource {
    private static final Logger logger = LoggerFactory.getLogger(BookResource.class);

    public List<Book> getBooks() {
        List<Book> books = new ArrayList<Book>(2);
        books.add(new Book("1416562605", "he White Tiger: A Novel"));
        books.add(new Book("1465438165", "Star Wars: The Force Awakens Visual Dictionary"));
        return books;

    public Book getBook(@PathParam("isbn") String isbn) {
        return new Book("1416562605", "he White Tiger: A Novel");

    public void createBook(Book book) {
        logger.info("Enters createBook() {} > {}", book.getIsbn(), book.getTitle());

Instance of Application is the main entry point for any Dropwizard application. Now our resource file has to be registered with the application like below:

public class DropwizardSkolApplication extends Application<DropwizardSkolConfiguration> {
    private static final String value = "Hello %s";

    public static void main(String[] args) throws Exception {
        new DropwizardSkolApplication().run(args);

    public void run(DropwizardSkolConfiguration dropwizardSkolConfiguration,
                    Environment environment) throws Exception {
        //Register resource
        BookResource bookResource = new BookResource();

Our first REST API development is done. Finally, compile and run the application using the following commands:

mvn package
java -jar target/dropwizardskol.jar server

Wouldn’t that be amazing? Now you can access your REST API using any client! Dropwizard is the right candidate for rapid, clean, and crisp REST API development!

I hope you have enjoyed this article. Let me know if you have any comments or feedback. Please share this article with your friends!

dropwizard, framework, maven, rest, rest api

Published at DZone with permission of Thamizh Arasu , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}