Lily is a lightweight framework for the rapid and easy development of live, real-time web applications in Scala.
Lily is built around and integrates flawlessly with ZIO HTTP and ZIO Streams.
The framework offloads the rendering heavy lifting to the server side (DOM) and communicates with the frontend via DOM diffing and binary WebSockets (CBOR).
It's a work in progress, so please expect changes. Please take a look at example apps for some inspiration.
object CounterExample extends LiveView[Any, Int]:
def state = ZStream.fromZIO(ZIO.succeed(0))
def on(s: Int) =
case on("increment" -> _) => ZIO.succeed(s + 1)
case on("decrement" -> _) => ZIO.succeed(s - 1)
case _ => ZIO.succeed(s)
def render(n: Int, path: Path): Task[Html] = ZIO.succeed:
Examples.layout(Some("Simple Counter Example"), Some(path))(
h1("Lily - Counter example"),
div(p(s"Counter is now: $n")),
div(p(s"Plus two is ${n + 2}")),
div(p(s"Some math: ${n * 1.2 * Math.PI}")),
div(
button("Increment").on("click" -> "increment"),
button("Decrement").on("click" -> "decrement")
)
)
// Add to your ZIO HTTP routes via:
private val routes =
Routes(
Method.GET / Root -> handler(Response.text("Hello, World!"))
)
++ LiveView.route(Path.empty / "counter-v2", examples.CounterExample)- Oto
- Use
devenvto get Java JDK. Check devenv.nix for more information. - Lily can be interactively developed with the help of
sbt-revolverwith:
sbt ~apps/reStart
sbt ~core/test- The server boots on http://localhost:3334