let's play- overview

Download Let's Play- Overview

Post on 10-May-2015

787 views

Category:

Technology

0 download

Embed Size (px)

DESCRIPTION

Introduce play framework from high level to code.

TRANSCRIPT

  • 1.LETS PLAYOverView Xuefeng.Wu 2013.07

2. AGENDA !Architecture Good things Bad things 3. M-V-C 4. PLAY 5. ROUTE/users/1 /users/:id controller.Users.get(id:Long) 6. ACTION request => response object Users extends Controller { def get(id: Long) = Action {request => Ok(User.findById(id).name) } } 7. OK(PLAY NAME>)Generates a 200 OK result. text/xml http body play 8. HTTP BODY Text, Json, XML, File Action(BodyParsers.parse.json) {request: Request[JsValue] => } 9. IN ONE SLID /users/:idcontroller.Users.get(id:Long)object Users extends Controller { def get(id: Long) = Action{request => val user = User.findById(id) Ok(Json.toJson(s {name: ${user.name}})) } } 10. PLAY INTRODUCE The Play Framework combines productivity and performance making it easy to build scalable web applications with Java and Scala. ! ! Play is developer friendly with a "just hit refresh" workow and built-in testing support. ! ! With Play, applications scale predictably due to a stateless and non-blocking architecture. ! ! By being RESTful by default, including assets compilers, JSON & WebSocket support, ! ! Play is a perfect t for modern web & mobile applications. 11. PLAY GOOD THINGS The Play Framework combines productivity and performance making it easy to build scalable web applications with Java and Scala. ! ! Play is developer friendly with a "justhit refresh" workow and built-intesting support. ! ! With Play, applications scale predictably due to a stateless and non-blocking architecture. ! ! By being RESTful by default, including assetscompilers, JSON &WebSocket support, ! ! Play is a perfect t for modernweb & mobile applications. 12. PRODUCTIVITYjust hit refresh v.s. restart jetty type safe v.s. more test 13. FIX AND HIT 14. PERFORMANCEcompiled v.s. intercept non-blocking v.s. one thread for one request 15. NON-BLOCKINGIteratee http://www.infoq.com/presentations/Play2 16. SCALABLEstateless v.s. session akka Cluster 17. SCALABLEstateless v.s. session akka Clusterhttp://es.slideshare.net/nicmarti/play-framework-softshake-presentation 18. BUILT-IN TESTINGplay.api.test.Helper._ 19. ASSETS COMPILERS CoffeeScript LESS CSS Google Closure Compiler RequireJS 20. JSON case class RegisterInfo(email: String, password: Option[String], partnerId: Option[String]) implicit val registerInfoReads = Json.reads[RegisterInfo] def result: BusinessResult[CreatedAccount] = Try(request.body.validate[RegisterInfo].get) match { case Success(registerInfo) => business.register(registerInfo) case Failure(e) => FailedResult(invalidJson, List(Messages("invalid.json.format"))) } 21. PLAY INTRODUCE The Play Framework combines productivity and performance making it easy to build scalable web applications with Java and Scala. ! ! Play is developer friendly with a "just hit refresh" workow and built-in testing support. ! ! With Play, applications scale predictably due to a stateless and non-blocking architecture. ! ! By being RESTful by default, including assets compilers, JSON & WebSocket support, ! ! Play is a perfect t formodern web& mobile applications. 22. MODERN WEB 23. MODERN WEB !Designing for mobile first (even if youre not building a mobile app) Build only single page apps Create and use your own REST API Sex sells applies to web apps http://blogs.atlassian.com/2012/01/modern-principles-in-web-development/ 24. ASYNCAsyncResult Streaming HTTP responses Comet sockets WebSockets 25. DOCUMENThttp://www.playframework.com/documentation 26. NOT SO GOODThe template engine Anorm 27. THE TEMPLATE ENGINElack of UI helper reload need compiler meaningless statichttp://en.wikipedia.org/wiki/Template_engine_(web) 28. ANORMwrite SQL by hand less transaction management 29. REAL TIME 30. Q&A