Play Framework
● General purpose
● (Aims to be) fully-blown web framework
● Part of Typesafe Reactive Platform
● For Java & Scala
● Popular (LinkedIn, Guardian, Klout, …)
● Not very well-suited for microservices...
● but still popular :)
Routes (conf/routes)
● Type safe!
● VERB [path with params] [controller action]
– GET / controllers.OpenGraphFetcher.index
– GET /clients/:id controllers.ClientsController.show(id: Long)
– PUT /orders/:clientid controllers.OrdersController.create(clientId: Int)
● Body params (POST, PUT etc.) have to be
handled by Play forms or manually (ugly!)
Controllers (app/controllers/*)
● Composable Actions
– Action: Request[A] => Result
– DBAction: Session => Result
– AuthAction: RequestWithUser[A] => Result
– …
● Can be async
Views (app/views/*)
● Type safe templating language (twirl)
● Meh (aka leave it to frontenders)
Coding!
1) Clone & run sample project
2) Add action that takes two params (login:
String, authToken: String), wire it to routes, test
3) Try authenticate your request with Redis
OpenGraph Info Fetcher
● Given list of URLs return OG info
● Synchronous? (request - response)
● Waiting for all OGs to fetch
● How to handle failure?
● Or maybe polling?
● No, websockets!
● Answers ASAP
● Failure? Just screw it
WebSockets
● Async of the web!
● Almost like good ol' TCP (BSD) sockets
Play-flavoured websockets:
● Iteratees (FP black magic, good for streams)
● Actors (❤, good for messages)
Akka
● Toolkit for distributed & concurrent systems
● Based on concept of actor and messaging
Actor:
● Encapsulates mutable state
● Reacts to messages
● Sends messages to other actors it knows:
● By address/name
● Because they send him message
● Because they were created by it
● ...
Actors in Akka
● Live in systems
● Can be distributed in space & time
● Process their messages sequentially
● No guarantees of message delivery/processing
● Can form tree-like hierarchies => supervision
Coding!
1) Write echo websocket using Akka Actors
2) Test it in web browser
3) Write not-so-stringly-typed websocket
4) Test it in web browser
5) Write proper types for task
6) Implement OG fetching
7) Test it in web browser
8) (For brave & ambitious) Implement caching