Skip to content

v1.0.0.0-RC18

Compare
Choose a tag to compare
@github-actions github-actions released this 09 Dec 11:54
· 1240 commits to main since this release

Changes

Highlights

This release packs server-side cookie support, middleware support and endpoints to make your apis typesafe.

Server Side Cookie Support

private val cookie = Cookie("org", "d11") @@ maxAge(5 seconds)
val res            = Response.ok.addCookie(cookie)

private val app = Http.collect[Request] {
  case Method.GET -> !! / "cookie" =>
    Response.ok.addCookie(cookie @@ path(!! / "cookie") @@ httpOnly)

  case Method.GET -> !! / "secure-cookie" =>
    Response.ok.addCookie(cookie @@ secure @@ path(!! / "secure-cookie"))

  case Method.GET -> !! / "cookie" / "remove" =>
    res.addCookie(cookie.clear)
}

Middleware Support

val app: HttpApp[Clock, Nothing] = Http.collectM[Request] {
  // this will return result instantly
  case Method.GET -> !! / "text"         => ZIO.succeed(Response.text("Hello World!"))
  // this will return result after 5 seconds, so with 3 seconds timeout it will fail
  case Method.GET -> !! / "long-running" => ZIO.succeed(Response.text("Hello World!")).delay(5 seconds)
}

val serverTime: Middleware[Clock, Nothing] = patchM((_, _) =>
  for {
    currentMilliseconds <- currentTime(TimeUnit.MILLISECONDS)
    withHeader = Patch.addHeaders(List(Header("X-Time", currentMilliseconds.toString)))
  } yield withHeader,
)

val middlewares: Middleware[Console with Clock, IOException] =
  // print debug info about request and response
  debug ++
    // close connection if request takes more than 3 seconds
    timeout(3 seconds) ++
    // add static header
    addHeader("X-Environment", "Dev") ++
    // add dynamic header
    serverTime

Server.start(8090, (app @@ middlewares).silent).exitCode

Typesafe Endpoint Support

def app = GET / "a" / *[Int] / "b" / *[Boolean] to { a =>
  Response.text(a.params.toString)
}

🚀 Features

Improvements

🐛 Bug Fixes

🧰 Maintenance

📓 Documentation and Examples

📈 Version Bumps