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:
- API featuring JSON and validation
- full-stack featuring HTML, static files and forms
- sharaf-todo-backend, implementation of the todobackend.com spec, featuring CORS handling
- OAuth2 login with Pac4J library
- PetClinic implementation, featuring full-stack app with Postgres db, config, integration tests etc.
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:
- querson for query parameters
- tupson for JSON
- formson for forms
- validson for validation
- hepek-components for HTML (with scalatags)
- requests for firing HTTP requests
- typesafe-config for configuration
Misc
Why name "sharaf"?
Å araf means a "screw" in Bosnian, which reminds me of scala spiral logo.