Skip to content

jac3km4/saul

Repository files navigation

saul

Write Scala APIs with types. This library allows you to derive HTTP routing for services from nothing else but type definitions (kind of like Haskell servant).

example

simple usage:

type Endpoint = POST as User / "users" / path[String]

val api =
  Servable[Endpoint].serve { (path: String, body: User) =>
    "ok"
  }

advanced usage with different routes and an ADT (example):

sealed trait UserRequest                                                  extends Product with Serializable
final case class DeleteProfile(email: String)                             extends UserRequest
final case class GetProfile(userId: String, includeEntitlements: Boolean) extends UserRequest

type Api =
  (GET / "users" / path[String] ? param["include-entitlements", Boolean] to GetProfile) <|>
  (DELETE / "users" / path[String] to DeleteProfile)

val api = Servable[Api]

val service = api.serve { req: UserRequest =>
  req match {
    case DeleteProfile(userId)                   => "not ok"
    case GetProfile(userId, includeEntitlements) => "ok"
  }
}

About

Write Scala APIs with types

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages