From f297405d8a57b31995a40217cdc51049ede88ea1 Mon Sep 17 00:00:00 2001 From: Peter Kotula Date: Thu, 15 Aug 2024 13:21:35 +0200 Subject: [PATCH] zio-http 3.0.0-RC9 (#873) --- docs/reconfigurable-logger.md | 4 +- .../zio/logging/api/http/ApiHandlers.scala | 39 ++++++++----------- .../example/ConfigurableLoggerApp.scala | 4 +- .../logging/api/http/ApiHandlersSpec.scala | 6 +-- project/Versions.scala | 2 +- 5 files changed, 25 insertions(+), 30 deletions(-) diff --git a/docs/reconfigurable-logger.md b/docs/reconfigurable-logger.md index d78da4cf..df5ccc06 100644 --- a/docs/reconfigurable-logger.md +++ b/docs/reconfigurable-logger.md @@ -222,8 +222,8 @@ object ConfigurableLoggerApp extends ZIOAppDefault { _ <- ZIO.logDebug("Done") @@ LogAnnotation.TraceId(traceId) } yield () - val httpApp: HttpApp[LoggerConfigurer] = - ApiHandlers.routes("example" :: Nil).toHttpApp @@ Middleware.basicAuth("admin", "admin") + val httpApp: Routes[LoggerConfigurer with Any, Nothing] = + ApiHandlers.routes("example" :: Nil) @@ Middleware.basicAuth("admin", "admin") override def run: ZIO[Scope, Any, ExitCode] = (for { diff --git a/examples/core/src/main/scala/zio/logging/api/http/ApiHandlers.scala b/examples/core/src/main/scala/zio/logging/api/http/ApiHandlers.scala index 0ddbf54c..45bb2911 100644 --- a/examples/core/src/main/scala/zio/logging/api/http/ApiHandlers.scala +++ b/examples/core/src/main/scala/zio/logging/api/http/ApiHandlers.scala @@ -15,47 +15,42 @@ */ package zio.logging.api.http -import zio.http.{ Handler, Route, Routes } +import zio.ZIO +import zio.http.{ Route, Routes } import zio.logging.LoggerConfigurer import zio.logging.api.http.ApiDomain.Error -import zio.{ LogLevel, ZIO } object ApiHandlers { def getLoggerConfigs(rootPath: Seq[String] = Seq.empty): Route[LoggerConfigurer, Nothing] = ApiEndpoints .getLoggerConfigs(rootPath) - .implement { - Handler.fromFunctionZIO[Unit] { _ => - LoggerConfigurer - .getLoggerConfigs() - .map(_.map(ApiDomain.LoggerConfig.from)) - .mapError(_ => Error.Internal()) - } + .implement { _ => + LoggerConfigurer + .getLoggerConfigs() + .map(_.map(ApiDomain.LoggerConfig.from)) + .mapError(_ => Error.Internal()) + } def getLoggerConfig(rootPath: Seq[String] = Seq.empty): Route[LoggerConfigurer, Nothing] = ApiEndpoints .getLoggerConfig(rootPath) - .implement { - Handler.fromFunctionZIO[String] { name => - LoggerConfigurer.getLoggerConfig(name).mapError(_ => Error.Internal()).flatMap { - case Some(r) => ZIO.succeed(ApiDomain.LoggerConfig.from(r)) - case _ => ZIO.fail(Error.NotFound()) - } + .implement { name => + LoggerConfigurer.getLoggerConfig(name).mapError(_ => Error.Internal()).flatMap { + case Some(r) => ZIO.succeed(ApiDomain.LoggerConfig.from(r)) + case _ => ZIO.fail(Error.NotFound()) } } def setLoggerConfigs(rootPath: Seq[String] = Seq.empty): Route[LoggerConfigurer, Nothing] = ApiEndpoints .setLoggerConfig(rootPath) - .implement { - Handler.fromFunctionZIO[(String, LogLevel)] { case (name, logLevel) => - LoggerConfigurer - .setLoggerConfig(name, logLevel) - .map(ApiDomain.LoggerConfig.from) - .mapError(_ => Error.Internal()) - } + .implement { case (name, logLevel) => + LoggerConfigurer + .setLoggerConfig(name, logLevel) + .map(ApiDomain.LoggerConfig.from) + .mapError(_ => Error.Internal()) } def routes(rootPath: Seq[String] = Seq.empty): Routes[LoggerConfigurer, Nothing] = diff --git a/examples/core/src/main/scala/zio/logging/example/ConfigurableLoggerApp.scala b/examples/core/src/main/scala/zio/logging/example/ConfigurableLoggerApp.scala index 08464280..8ce8ae6f 100644 --- a/examples/core/src/main/scala/zio/logging/example/ConfigurableLoggerApp.scala +++ b/examples/core/src/main/scala/zio/logging/example/ConfigurableLoggerApp.scala @@ -75,8 +75,8 @@ object ConfigurableLoggerApp extends ZIOAppDefault { _ <- ZIO.logDebug("Done") @@ LogAnnotation.TraceId(traceId) } yield () - val httpApp: HttpApp[LoggerConfigurer] = - ApiHandlers.routes("example" :: Nil).toHttpApp @@ Middleware.basicAuth("admin", "admin") + val httpApp: Routes[LoggerConfigurer with Any, Nothing] = + ApiHandlers.routes("example" :: Nil) @@ Middleware.basicAuth("admin", "admin") override def run: ZIO[Scope, Any, ExitCode] = (for { diff --git a/examples/core/src/test/scala/zio/logging/api/http/ApiHandlersSpec.scala b/examples/core/src/test/scala/zio/logging/api/http/ApiHandlersSpec.scala index 0b72f36c..64386104 100644 --- a/examples/core/src/test/scala/zio/logging/api/http/ApiHandlersSpec.scala +++ b/examples/core/src/test/scala/zio/logging/api/http/ApiHandlersSpec.scala @@ -32,7 +32,7 @@ object ApiHandlersSpec extends ZIOSpecDefault { for { request <- ZIO.attempt(Request.get(URL.decode("/example/logger").toOption.get)) - response <- routes.toHttpApp.runZIO(request) + response <- routes.runZIO(request) content <- HttpCodec.content[List[ApiDomain.LoggerConfig]].decodeResponse(response) } yield assertTrue(response.status.isSuccess) && assertTrue( content == List(ApiDomain.LoggerConfig("root", LogLevel.Info)) @@ -42,7 +42,7 @@ object ApiHandlersSpec extends ZIOSpecDefault { val routes = ApiHandlers.routes("example" :: Nil) for { request <- ZIO.attempt(Request.get(URL.decode("/example/logger/example.Service").toOption.get)) - response <- routes.toHttpApp.runZIO(request) + response <- routes.runZIO(request) content <- HttpCodec.content[ApiDomain.LoggerConfig].decodeResponse(response) } yield assertTrue(response.status.isSuccess) && assertTrue( content == ApiDomain.LoggerConfig("example.Service", LogLevel.Info) @@ -59,7 +59,7 @@ object ApiHandlersSpec extends ZIOSpecDefault { HttpCodec.content[LogLevel].encodeRequest(LogLevel.Warning).body ) ) - response <- routes.toHttpApp.runZIO(request) + response <- routes.runZIO(request) content <- HttpCodec.content[ApiDomain.LoggerConfig].decodeResponse(response) } yield assertTrue(response.status.isSuccess) && assertTrue( content == ApiDomain.LoggerConfig("example.Service", LogLevel.Warning) diff --git a/project/Versions.scala b/project/Versions.scala index 1c7c14e1..2a7e17e6 100644 --- a/project/Versions.scala +++ b/project/Versions.scala @@ -10,6 +10,6 @@ object Versions { val zioConfig = "4.0.2" val zioParser = "0.1.10" val zioPrelude = "1.0.0-RC28" - val zioHttp = "3.0.0-RC6" + val zioHttp = "3.0.0-RC9" val log4jVersion = "2.23.1" }