Created
January 14, 2019 14:40
-
-
Save tomwadeson/b5999cb5c9fc3ac6b9e87418a3d27c84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.effect.{ExitCode, IO, IOApp, Resource} | |
import org.http4s.HttpRoutes | |
import org.http4s.client.Client | |
import org.http4s.client.blaze.BlazeClientBuilder | |
import org.http4s.dsl.Http4sDsl | |
import org.http4s.implicits._ | |
import cats.implicits._ | |
object Http4sClientTest extends IOApp { | |
override def run(args: List[String]): IO[ExitCode] = { | |
val client: Resource[IO, Client[IO]] = | |
// realClient.map(c => org.http4s.client.middleware.RequestLogger(true, true)(c)) | |
stubClient.map(c => org.http4s.client.middleware.RequestLogger(true, true)(c)) | |
(client use { c => | |
c.expect[String]("https://www.wikipedia.org/").map(_ => println("Done")) | |
}).as(ExitCode.Success) | |
} | |
val realClient: Resource[IO, Client[IO]] = | |
BlazeClientBuilder[IO](scala.concurrent.ExecutionContext.global).resource | |
val stubClient: Resource[IO, Client[IO]] = { | |
val dsl = Http4sDsl[IO] | |
import dsl._ | |
val stubHttpApp = HttpRoutes | |
.of[IO] { | |
case _ => | |
Ok("Everything's dandy.") | |
} | |
.orNotFound | |
Resource.pure(Client.fromHttpApp(stubHttpApp)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment