Skip to content
lolgabPublic

About

Scala Native HTTP server based on FreeUnit

Topics

Resources

Stars

150 stars

Watchers

6 watching

Forks

Latest commit

 

History

280 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SNUnit: Scala Native HTTP server based on FreeUnit

//> 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.

Documentation

The documentation is at https://lolgab.github.io/snunit/.

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.

Quick start

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 | bash

Save the example above as Hello.scala and run it:

snunit run Hello.scala

This builds the app and serves it on http://localhost:8080. To build the executable to deploy:

snunit package Hello.scala -o hello
./hello

With sbt you don't need the CLI: there is an sbt-snunit plugin.

Changelog

See CHANGELOG.md.

License

Apache 2.0, see LICENSE.

About

Scala Native HTTP server based on FreeUnit

Topics

Resources

Stars

150 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages