Simple REST with Dropwizard
Intro, Structure, Resources, DeploymentBucharest JUG #5 @ Cegeka
Founder @ Axemblr.comApache Whirr PMC memberjclouds committer
Connect with me on LinkedIn
Andrei Savu
DisclaimerHighly 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 thingRepresentation = 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', '[email protected]'}
POST /todos?email=x {'email': '[email protected]'}
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
API
Database
Architectures #2
Web UI
API Database
Mobile
Architectures #3
Web UI
APIInternal Platform
APIs
Mobile
Database
Queues
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 ApplicationStructure, Configuration, Deployment
"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
Specification
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
Structure, Configuration, Testing
To the IDE!
Dedicated repository with restricted access.
Cool tool: etckeeper (debian)
Production Configuration
Run tests on the local machine
Fabric / CapistranoSupervisor / UpstartMonitGanglia / Nagios / Cloudwatch / SNS
Deployment: Start Simple
Deployment: Automate
Continuous Integration
Puppet / Chef1-step deployment from a specific branch
Ability to rebuild from a vanilla OS installLeverage 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?
● Demo code:https://github.com/bucharest-jug/dropwizard-todo
● All about Dropwizard:http://dropwizard.codahale.com/
● API Grove: API management:http://apigrove.net/
Resources
Top Related