Rapid REST API Development With Dropwizard

DZone 's Guide to

Rapid REST API Development With Dropwizard

Learn how to create your own REST API with Java and Dropwizard with this practical tutorial.

· Integration 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 straightforward? Probably NOT!

But one framework  I evaluated recently has most of the plus-points, and it allowed me to focus on my business problem instead of the plumbing work to prepare the infrastructure. This tool is none other than “Dropwizard.”

This tiny framework came very late in the market when compared to most of the other frameworks, but it attracted developers' attention in a shorter time. In 2012 it was mentioned in the Thoughtworks technology radar as a “TRIAL.” It jumped to “ADAPT” within 2 years (see 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 BOX. It contains all the good parts required for easy development. For example, it contains the following well-known APIs/frameworks to ease our development.

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

Ok, we have seen some of the good parts of the Dropwizard framework. In the next section we will 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 classDropwizardSkolApplication 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=newBookResource();

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 clean and crisp RAPID 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…

api, framework, rest, rest api, thoughtworks

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 }}