//> using dep com.github.lolgab::snunit::0.13.0
import snunit.*
@main
def run =
SyncServerBuilder
.setRequestHandler(req =>
req.send(
statusCode = StatusCode.OK,
content = "Hello world!\n",
headers = Headers("Content-Type" -> "text/plain")
)
)
.build()
.listen()SNUnit is a Scala Native library to write HTTP server applications on top of FreeUnit, the community LTS fork of NGINX Unit. It allows you to write both synchronous and asynchronous web servers with automatic restart on crashes, automatic load balancing of multiple processes, great performance and all the nice FreeUnit features.
An SNUnit application is a single executable. It embeds unitd, starts it
with a generated configuration and then runs itself as the application. There is
nothing to install besides the snunit command line tool.
You can use SNUnit directly, as in the example above, or through http4s, Tapir, Cask, Undertow and endpoints4s.
The documentation is at https://lolgab.github.io/snunit/.
- Getting started
- sbt and other build tools
- How it works
- Configuration
- Libraries: http4s, Tapir, Cask, Undertow, endpoints4s
- Observability: traces, metrics and logs, the observability stack, tracing with otel4s
Its sources are the Markdown files in docs/. GitHub Pages builds them with Jekyll on every push to main.
To preview them locally: jekyll serve --source docs.
Install scalino, then the snunit command line tool
(Linux and macOS, x86_64 and aarch64):
curl -fsSL https://raw.githubusercontent.com/lolgab/snunit/main/install.sh | bashSave the example above as Hello.scala and run it:
snunit run Hello.scalaThis builds the app and serves it on http://localhost:8080. To build the executable to deploy:
snunit package Hello.scala -o hello
./helloWith sbt you don't need the CLI: there is an
sbt-snunit plugin.
See CHANGELOG.md.
Apache 2.0, see LICENSE.