Created
February 22, 2024 14:34
-
-
Save TimWSpence/47756ab75dd4fffc3b8320c9e8605dfd to your computer and use it in GitHub Desktop.
This file contains 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
//> using scala 3 | |
//> using toolkit typelevel:default | |
import cats.syntax.all.* | |
import cats.effect.* | |
import org.http4s.ember.client.EmberClientBuilder | |
import org.http4s.* | |
import org.http4s.circe.CirceEntityDecoder.* | |
import org.http4s.implicits.* | |
import org.http4s.headers.Authorization | |
import org.http4s.headers.Accept | |
import io.circe.Json | |
object Repro extends IOApp.Simple: | |
val run = EmberClientBuilder | |
.default[IO] | |
.build | |
.use: client => | |
val request = Request[IO]( | |
method = Method.GET, | |
uri = uri"http://neverssl.com" | |
) | |
client | |
.run(request) | |
.use: resp => | |
resp | |
.attemptAs[Json] | |
.value | |
.flatMap: | |
case Right(body) => IO.unit | |
case Left(err) => | |
resp.bodyText.compile.foldMonoid.flatMap(IO.println) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment