silicon valley code camp 2011: play! as you rest
Post on 19-Oct-2014
2.506 views
DESCRIPTION
My talk from Silicon Valley Code Camp 2011 on PlayFramework.TRANSCRIPT
![Page 1: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/1.jpg)
Play! as you REST
Using Play! Framework to build RESTful Services
Silicon Valley Code CampOctober 8th, 2011
![Page 2: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/2.jpg)
Agenda
• RESTful Interface• Traditional J2EE Development• Rise of developer-friendly and fun frameworks• Play! Framework Overview• Working Session – Implement and Deploy a
RESTful service using Play! Framework (Java).
![Page 3: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/3.jpg)
What is REST
• It supports HTTP as the Transport Protocol• The HTTP verbs map to the action being performed
on a resource• The resource is the noun on which an action is being
performed. The noun is generally qualified by an identifier.
• The noun is a business entity, a part of the model.• REST is not a standard, but an architecture. Hence
everyone tends to explain it differently but drives to the same meaning.
![Page 4: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/4.jpg)
Examples of RESTful URLs• GET /v1/person/1234
• POST /v1/person/1234/status{“status”: “Hello, developers!”}
• DELETE /elasticsearch/people/status/_mapping
• PUT /v2.0/photos/e5c2f436-f149-11e
• GET /v1.0/social/rest/people/nickname.mpanditign/@friends
• GET https://accounts.google.com/o/oauth2/token
![Page 5: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/5.jpg)
Traditional J2EE Web Development
1. Code a servlet (or something that becomes a servlet down the line) using Jersey or Spring, etc.
2. Stick the name and path in a web.xml3. Package a war file via a build process like ant,
maven, ivy, etc.4. Copy the war file in the container’s webapp folder5. Bounce the server6. Pray that it works, if not, go to step 1.
![Page 6: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/6.jpg)
Rise of Developer-friendly Frameworks
• Faster turnaround and prototyping• No need for build -> deploy -> fix -> build cycle• Integrated Testing Support via Specs• Convention over Configuration• Lightweight, focused towards making rapid
development and deployment a priority. • Developers can focus on the fun stuff, instead
of writing configurations and build scripts
![Page 7: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/7.jpg)
Play! Framework
• Inspired by Django and Rails• A complete web-framework offering:
– A Server (netty)– IDE integration with Eclipse, TextMate, IntelliJ– Templating Language (Groovy, Scala [2.0])– RESTful by being on a share-nothing, stateless architecture– Modules for all major dependencies and seamless integration– Hot Reload - you need the IDE and the Browser. No build scripts.– Convention Over Configuration– None of the J2EE bloat
![Page 8: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/8.jpg)
Play! Overview
![Page 9: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/9.jpg)
Play! Components
• The Controller – Which gets requests, and has the logic to process them
and generate a response by interacting with the Model• The routes file– Where URLs are mapped to Controller Methods
• The View– Templates, etc. to render the response from the
controller• The Model– The “beans” or data-aware domain objects.
![Page 10: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/10.jpg)
Demo Time!
• Download Play! 1.2.3 • Build a simple Play! Java Application• Go over the folder structure• eclipsify it, pull in Eclipse• Demonstrate the hot-reload– Add a new method in the controller
• Run tests via the built-in TestRunner– Mess up a test– Add a new test for the new method
![Page 11: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/11.jpg)
More Goodies hidden in Play!
• Quick persistence without a database?– db=mem
• Memcached support• MySQL and PostgreSQL support• Test Data stored as Fixtures in a YAML• Modes – dev, production
– dev shows detailed errors with source code• Mail hosts• Scheduled Jobs via annotations (demo later?)• Built in Logger, so you wont work with awesome log4j
configs.
![Page 12: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/12.jpg)
Bundled Libraries
• Play comes bundled with– ehcache– hibernate ORM– apache commons– Google Gson– ezmorph– MySQL and Postgres drivers– memcached driver– xstream for XML– Antlr– …and more!
![Page 13: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/13.jpg)
Let’s build an API
• A system to store and query users– Create a (very) simple model – Use MongoDB to persist the model in the db
![Page 14: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/14.jpg)
Service Endpoints
• GET all users /users• GET a user by ID /users/{id}• DELETE a user by ID /users/{id}• POST (create) a new user /users• PUT (update) a user /users/{id}
![Page 15: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/15.jpg)
Things I am not covering
• Custom deserialization of Mongo ObjectId() with Gson
• Merges on Updates• Caching using built-in Cache façade
![Page 16: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/16.jpg)
What to look forward to
• Play! 2.0– Scala as the templating language– Support for sbt as the build system (vs. Python)– Stateless JPA called Ebean instead of Hibernate– Native support for both Java and Scala
![Page 17: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/17.jpg)
We’re hiring!corp.ign.com/careers, and @ignjobs
• Scala• Java• PHP/Zend• Rails• ElasticSearch• MongoDB• MySQL• HTML5
• Jquery Mobile• Sencha Touch• Phonegap• Wordpress• ActionScript/Flash• Redis/Memcached• CI/CD
![Page 18: Silicon Valley Code Camp 2011: Play! as you REST](https://reader035.vdocument.in/reader035/viewer/2022081813/54448713b1af9f600a8b496b/html5/thumbnails/18.jpg)
About
Manish Pandit Sr. Engineering ManagerIGN Entertainment
http://linkedin.com/in/mpandit@lobster1234