Quickstart 🔗

This lesson starts a Sharaf server and makes one request. You need JDK 21 and Scala CLI installed.

Create a file named hello.sc with this content:

//> using scala "3.7.3"
//> using dep ba.sake::sharaf-undertow:0.19.0

import ba.sake.sharaf.*
import ba.sake.sharaf.undertow.UndertowSharafServer

val routes = Routes:
  case GET -> Path("hello", name) =>
    Response.withBody(s"Hello $name")
  case GET -> _ =>
    Response.withBody("Go to http://localhost:8181/hello/your-name")

UndertowSharafServer("localhost", 8181, routes).start()

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

Run it from the directory containing the file:

scala hello.sc

In another terminal, make a request:

curl http://localhost:8181/hello/Bob

The response is Hello Bob. Stop the server with Ctrl-C.

The route matches a GET request whose path begins with hello and captures the next segment as name. Continue with path parameters, or see dependency setup for Mill and sbt.

More examples 🔗

Hello World ➡️