Simple REST with
       Dropwizard
Intro, Structure, Resources, Deployment
      Bucharest JUG #5 @ Cegeka
Andrei Savu
Founder @ Axemblr.com
Apache Whirr PMC member
jclouds committer

Connect with me on LinkedIn
Disclaimer
Highly Technical, Opinionated Talk
REST
(Representation State Transfer)

Browser Analogy: Fetch representation of the
current state of a resource (page)

Makes extensive use of HTTP semantics
Resource & Representation
Resource = the real thing
Representation = server responses

"A request interacts with a resource and
receives a representation."
REST Verbs
Match HTTP semantics:

●   GET : read resources, safe, cache friendly
●   POST : update resources, create
●   PUT : replace entire resource, atomic
●   DELETE : delete entire resource, atomic

● HEAD
● PATCH
REST Batch Operations
A request can act on a single resource or a
class of resources.

E.g.

POST /todos/1 {'email', 'new@example.com'}

POST /todos?email=x {'email': 'other@x.com'}
REST Transport
HTTP

With representations as JSON or XML

Negotiation with Accept & Content-Type
headers

Supports caching, If-Modified-Since queries
Architectures #1


             Web UI



                      Database




              API
Architectures #2

             Web UI




              API     Database




             Mobile
Architectures #3

      Web UI              Database




               Internal
       API     Platform   Queues
                 APIs




      Mobile               Other
Dropwizard
Thanks Yammer (Coda Hale) for making it
open source!

Framework for JVM-based backend services

"Dropwizard has out-of-the-box support for sophisticated configuration,
application metrics, logging, operational tools, and much more, allowing you
and your team to ship a production-quality HTTP+JSON web service in the
shortest time possible."
Components
●   Jetty for HTTP
●   Jersey for REST
●   Jackson for JSON
●   Metrics for metrics

● And: guava, logback, hibernate validator,
  jersey client libraries, jdbi, freemarker

http://dropwizard.codahale.com/getting-started/
Demo Application
Structure, Configuration, Deployment
Specification
"A simple todo list sample application implemented using
Dropwizard as the core framework with a simple UI that
consumes the REST API based on twitter bootstrap,
backbone.js, jquery and jasmine."



https://github.com/bucharest-jug/dropwizard-todo
REST Endpoints
GET /todos | GET /todos/{id}

POST /todos

PUT /todos/{id}

DELETE /todos | DELETE /todos/{id}
Resources: Todo List

● id : assigned by server on creation (Read
  Only)
● created : assigned on creation
● email: owner email address
● items: list of items
Resources: Todo Item

● title: a text description of what need to be
  done
● created: date time assigned on creation
● finished: date time assigned when the item
  was finished
To the IDE!
Structure, Configuration, Testing
Production Configuration
Dedicated repository with restricted access.

Cool tool: etckeeper (debian)
Deployment: Start Simple
Run tests on the local machine

Fabric / Capistrano
Supervisor / Upstart
Monit
Ganglia / Nagios / Cloudwatch / SNS
Deployment: Automate
Continuous Integration

Puppet / Chef
1-step deployment from a specific branch

Ability to rebuild from a vanilla OS install
Leverage cloud infrastructure for Dev & QA
Deployment: Continuous
High quality test suite (unit + live + smoke)
Continuous Deployment Pipeline

All new code is deployed to multiple
environments and production.

OpenAgile Timisoara anyone?
Resources
● Demo code:
  https://github.com/bucharest-jug/dropwizard-todo


● All about Dropwizard:
  http://dropwizard.codahale.com/


● API Grove: API management:
  http://apigrove.net/
Thanks!
asavu@apache.org

Simple REST with Dropwizard

  • 1.
    Simple REST with Dropwizard Intro, Structure, Resources, Deployment Bucharest JUG #5 @ Cegeka
  • 2.
    Andrei Savu Founder @Axemblr.com Apache Whirr PMC member jclouds committer Connect with me on LinkedIn
  • 3.
  • 4.
    REST (Representation State Transfer) BrowserAnalogy: Fetch representation of the current state of a resource (page) Makes extensive use of HTTP semantics
  • 5.
    Resource & Representation Resource= the real thing Representation = server responses "A request interacts with a resource and receives a representation."
  • 6.
    REST Verbs Match HTTPsemantics: ● GET : read resources, safe, cache friendly ● POST : update resources, create ● PUT : replace entire resource, atomic ● DELETE : delete entire resource, atomic ● HEAD ● PATCH
  • 7.
    REST Batch Operations Arequest can act on a single resource or a class of resources. E.g. POST /todos/1 {'email', 'new@example.com'} POST /todos?email=x {'email': 'other@x.com'}
  • 8.
    REST Transport HTTP With representationsas JSON or XML Negotiation with Accept & Content-Type headers Supports caching, If-Modified-Since queries
  • 9.
    Architectures #1 Web UI Database API
  • 10.
    Architectures #2 Web UI API Database Mobile
  • 11.
    Architectures #3 Web UI Database Internal API Platform Queues APIs Mobile Other
  • 12.
    Dropwizard Thanks Yammer (CodaHale) for making it open source! Framework for JVM-based backend services "Dropwizard has out-of-the-box support for sophisticated configuration, application metrics, logging, operational tools, and much more, allowing you and your team to ship a production-quality HTTP+JSON web service in the shortest time possible."
  • 13.
    Components ● Jetty for HTTP ● Jersey for REST ● Jackson for JSON ● Metrics for metrics ● And: guava, logback, hibernate validator, jersey client libraries, jdbi, freemarker http://dropwizard.codahale.com/getting-started/
  • 14.
  • 15.
    Specification "A simple todolist sample application implemented using Dropwizard as the core framework with a simple UI that consumes the REST API based on twitter bootstrap, backbone.js, jquery and jasmine." https://github.com/bucharest-jug/dropwizard-todo
  • 16.
    REST Endpoints GET /todos| GET /todos/{id} POST /todos PUT /todos/{id} DELETE /todos | DELETE /todos/{id}
  • 17.
    Resources: Todo List ●id : assigned by server on creation (Read Only) ● created : assigned on creation ● email: owner email address ● items: list of items
  • 18.
    Resources: Todo Item ●title: a text description of what need to be done ● created: date time assigned on creation ● finished: date time assigned when the item was finished
  • 19.
    To the IDE! Structure,Configuration, Testing
  • 20.
    Production Configuration Dedicated repositorywith restricted access. Cool tool: etckeeper (debian)
  • 21.
    Deployment: Start Simple Runtests on the local machine Fabric / Capistrano Supervisor / Upstart Monit Ganglia / Nagios / Cloudwatch / SNS
  • 22.
    Deployment: Automate Continuous Integration Puppet/ Chef 1-step deployment from a specific branch Ability to rebuild from a vanilla OS install Leverage cloud infrastructure for Dev & QA
  • 23.
    Deployment: Continuous High qualitytest suite (unit + live + smoke) Continuous Deployment Pipeline All new code is deployed to multiple environments and production. OpenAgile Timisoara anyone?
  • 24.
    Resources ● Demo code: https://github.com/bucharest-jug/dropwizard-todo ● All about Dropwizard: http://dropwizard.codahale.com/ ● API Grove: API management: http://apigrove.net/
  • 25.