Skip to content

Instantly share code, notes, and snippets.

@TimWSpence
Created February 22, 2024 14:34
Show Gist options
  • Save TimWSpence/47756ab75dd4fffc3b8320c9e8605dfd to your computer and use it in GitHub Desktop.
Save TimWSpence/47756ab75dd4fffc3b8320c9e8605dfd to your computer and use it in GitHub Desktop.
//> 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