Skip to content

Instantly share code, notes, and snippets.

@obszczymucha
Created April 5, 2020 07:27
Show Gist options
  • Save obszczymucha/0f58afc32eaf9caa87694b2e38d70a43 to your computer and use it in GitHub Desktop.
Save obszczymucha/0f58afc32eaf9caa87694b2e38d70a43 to your computer and use it in GitHub Desktop.
object HealthCheckRoute {
implicit val healthCheckEncoder: Encoder[HealthCheck] = deriveEncoder[HealthCheck]
implicit def healthCheckEntityEncoder[F[_] : Sync]: EntityEncoder[F, HealthCheck] = jsonEncoderOf
def healthCheck[F[_] : Sync](service: HealthCheckService[F]): HttpRoutes[F] = {
val dsl = new Http4sDsl[F]() {}
import dsl._
HttpRoutes.of[F] {
case GET -> Root / "health-check" => for {
healthCheck <- service.healthCheck
response <- healthCheck.fold(l => ServiceUnavailable(l), r => Ok(r))
} yield response
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment