The Scala Toolkit

Building web servers with Cask

Language

Cask is an HTTP micro-framework, providing a simple and flexible way to build web applications.

Its main focus is on the ease of use, which makes it ideal for newcomers, at the cost of eschewing some features other frameworks provide, like asynchronicity.

To define an endpoint it’s enough to annotate a function with an annotation specifying the request path. Cask allows for building the response manually using tools that the library provides, specifying the content, headers, status code, etc. An endpoint function can also return a string, a uPickle JSON type, or a Scalatags template. In that case, Cask will automatically create a response with the appropriate headers.

Cask comes bundled with the uPickle library for handling JSONs, supports WebSockets and allows for extending endpoints with decorators, which can be used to handle authentication or rate limiting.

You can declare a dependency on Cask with the following using directive:

//> using dep com.lihaoyi::cask::0.9.2

In your build.sbt, you can add a dependency on Cask:

lazy val example = project.in(file("example"))
  .settings(
    scalaVersion := "3.4.2",
    libraryDependencies += "com.lihaoyi" %% "cask" % "0.9.2",
    fork := true
  )

In your build.sc, you can add a dependency on Cask:

object example extends RootModule with ScalaModule {
  def scalaVersion = "3.3.4"
  def ivyDeps = Agg(
    ivy"com.lihaoyi::cask::0.9.2"
  )
}

Contributors to this page: