sake92 / sharaf   0.0.15

Apache License 2.0 GitHub

Minimalistic Scala 3 web framework

Scala versions: 3.x

Sharaf 🔩

Simple, intuitive, batteries-included web framework.

Still WIP :construction: but very much usable. :construction_worker:

Usage

mill:

def ivyDeps = Agg(ivy"ba.sake::sharaf:0.0.15")

def scalacOptions = Seq("-Yretain-trees")

sbt:

libraryDependencies ++= Seq("ba.sake" %% "sharaf" % "0.0.15")

scalacOptions ++= Seq("-Yretain-trees")

scala-cli:

//> using dep ba.sake::sharaf:0.0.15

scala-cli  --scalac-option -Yretain-trees  my_script.sc

Examples

A hello world example in scala-cli:

//> using dep ba.sake::sharaf:0.0.15

import io.undertow.Undertow
import ba.sake.sharaf.*, routing.*

val routes = Routes:
  case GET() -> Path("hello", name) =>
    Response.withBody(s"Hello $name")

val server = Undertow
  .builder()
  .addHttpListener(8181, "localhost")
  .setHandler(SharafHandler(routes))
  .build()

server.start()

println(s"Server started at http://localhost:8181")

You can run it like this:

scala-cli  --scalac-option -Yretain-trees  examples/scala-cli/hello.sc 

Then you can go to http://localhost:8181/hello/Bob
to try it out.


Full blown standalone examples:

Why sharaf?

Simplicity and ease of use is the main focus of sharaf.

It is built on top of Undertow.
This means you can use awesome libraries built for Undertow, like pac4j for security and similar.
Also, you can leverage Undertow's lower level API, e.g. for WebSockets.

Sharaf bundles a set of libraries:

Misc

Why name "sharaf"?

Šaraf means a "screw" in Bosnian, which reminds me of scala spiral logo.