Skip to content

Commit

Permalink
zio-http 3.0.0-RC9 (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoon authored Aug 15, 2024
1 parent 39a8ca1 commit f297405
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 30 deletions.
4 changes: 2 additions & 2 deletions docs/reconfigurable-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 17 additions & 22 deletions examples/core/src/main/scala/zio/logging/api/http/ApiHandlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit f297405

Please sign in to comment.