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).
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"
}
}