Architecting Event-Driven Web,Mobile, and RESTful Apps – James Ward – Scala



Architecting Event-Driven Web,Mobile, and RESTful Apps – James Ward – Scala

0 2


architecting-event-driven-web-mobile-and-restful-apps


On Github jamesward / architecting-event-driven-web-mobile-and-restful-apps

@_JamesWard

Architecting Event-Driven Web,Mobile, and RESTful Apps

James Ward

Event-Driven Web Architecture

Event-Driven Use Cases

  • Compositional
  • Non-Blocking
  • Real-Time

Scala

The Modern JVM Language

  • Type-safe, Functional & Object Oriented
  • Interop with Java Libraries
  • Concise expressions for complex behavior
  • Built-in library for handling concurrency & asynchronous tasks

Basic App

object Hello extends App {
  println("hello, world")
}

Case Classes

case class Greeting(name: String) {
  def sayHello = "hello, " + name
}

object Hello extends App {
  val greeting = Greeting("James")
  println(greeting.sayHello)
}

Futures

Built-in Multi-Threading

import scala.concurrent._
import ExecutionContext.Implicits.global

def pause(msg: String, duration: Int) = {
  println(s"pausing for $duration seconds")
  Thread.sleep(1000 * duration)
  println(s"paused for $duration seconds")
  msg
}

val aa: Future[String] = future { pause("three", 3) }
val bb: Future[String] = future { pause("one", 1) }
val cc: Future[String] = future { pause("two", 2) }

println(Await.result(aa, duration.Duration.Inf))
println(Await.result(bb, duration.Duration.Inf))
println(Await.result(cc, duration.Duration.Inf))

For Comprehensions

for {
  j <- 1 to 3
  k <- j to 3
} yield k

Play Framework

The High Velocity Web Framework For Java and Scala

  • "Just Hit Refresh" Workflow
  • Scalable: Asynchronous, Non-Blocking, & Real-time
  • Modern Web: REST + JSON & Asset Compilers

Techniques

  • Async
  • Reactive = Async + Non-Blocking
  • Messaging: Comet, SSE, WebSockets