Simple REST with Dropwizard

25
Simple REST with Dropwizard Intro, Structure, Resources, Deployment Bucharest JUG #5 @ Cegeka

description

A quick introduction on REST and Dropwizard for Bucharest Java User Group 5 - http://bjug.ro/

Transcript of Simple REST with Dropwizard

Page 1: Simple REST with Dropwizard

Simple REST with Dropwizard

Intro, Structure, Resources, DeploymentBucharest JUG #5 @ Cegeka

Page 2: Simple REST with Dropwizard

Founder @ Axemblr.comApache Whirr PMC memberjclouds committer

Connect with me on LinkedIn

Andrei Savu

Page 3: Simple REST with Dropwizard

DisclaimerHighly Technical, Opinionated Talk

Page 4: Simple REST with Dropwizard

REST

(Representation State Transfer)

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

Makes extensive use of HTTP semantics

Page 5: Simple REST with Dropwizard

Resource & Representation

Resource = the real thingRepresentation = server responses

"A request interacts with a resource and receives a representation."

Page 6: Simple REST with Dropwizard

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

Page 7: Simple REST with Dropwizard

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

Page 8: Simple REST with Dropwizard

REST Transport

HTTP

With representations as JSON or XML

Negotiation with Accept & Content-Type headers

Supports caching, If-Modified-Since queries

Page 9: Simple REST with Dropwizard

Architectures #1

Web UI

API

Database

Page 10: Simple REST with Dropwizard

Architectures #2

Web UI

API Database

Mobile

Page 11: Simple REST with Dropwizard

Architectures #3

Web UI

APIInternal Platform

APIs

Mobile

Database

Queues

Other

Page 12: Simple REST with Dropwizard

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."

Page 13: Simple REST with Dropwizard

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/

Page 14: Simple REST with Dropwizard

Demo ApplicationStructure, Configuration, Deployment

Page 15: Simple REST with Dropwizard

"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

Page 16: Simple REST with Dropwizard

REST Endpoints

GET /todos | GET /todos/{id}

POST /todos

PUT /todos/{id}

DELETE /todos | DELETE /todos/{id}

Page 17: Simple REST with Dropwizard

Resources: Todo List

● id : assigned by server on creation (Read Only)

● created : assigned on creation● email: owner email address● items: list of items

Page 18: Simple REST with Dropwizard

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

Page 19: Simple REST with Dropwizard

Structure, Configuration, Testing

To the IDE!

Page 20: Simple REST with Dropwizard

Dedicated repository with restricted access.

Cool tool: etckeeper (debian)

Production Configuration

Page 21: Simple REST with Dropwizard

Run tests on the local machine

Fabric / CapistranoSupervisor / UpstartMonitGanglia / Nagios / Cloudwatch / SNS

Deployment: Start Simple

Page 22: Simple REST with Dropwizard

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

Page 23: Simple REST with Dropwizard

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?

Page 24: Simple REST with Dropwizard

● Demo code:https://github.com/bucharest-jug/dropwizard-todo

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

● API Grove: API management:http://apigrove.net/

Resources