Skip to content

Instantly share code, notes, and snippets.

@adamw
Created June 7, 2019 19:18
Show Gist options
  • Save adamw/c2f54f8276d7d5657ad492c6724f3d13 to your computer and use it in GitHub Desktop.
Save adamw/c2f54f8276d7d5657ad492c6724f3d13 to your computer and use it in GitHub Desktop.
package tapir.example
import org.http4s.{EntityBody, HttpRoutes}
import scalaz.zio.{IO, Task}
import tapir.Endpoint
import tapir.server.http4s.Http4sServerOptions
import scalaz.zio.interop.catz._
import tapir.server.ServerEndpoint
package object zio {
implicit class ZioEndpoint[I, E, O](e: Endpoint[I, E, O, EntityBody[Task]]) {
def toZioRoutes(logic: I => IO[E, O])(
implicit serverOptions: Http4sServerOptions[Task]): HttpRoutes[Task] = {
import tapir.server.http4s._
e.toRoutes(i => logic(i).either)
}
def zioServerLogic(logic: I => IO[E, O]):
ServerEndpoint[I, E, O, EntityBody[Task], Task] =
ServerEndpoint(e, logic(_).either)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment