I am currently trying to write extension for external API using http4s Client and Server tools.
My idea was: when endpoint, which I created using Server is triggered, make multiple requests (to same endpoint on external API, but with different parameters) using Client, do some operations on the data received in every of this request (for example, sum all Int
fields from data), and then unite result of operations in single list and return this list. Since all request results is wrapped in IO, return value for method I created is List[IO[Int]]
, but I cant find how to decode it to use in response when endpoint is triggered.
I can sucsessfully return in responce single IO[Int] using the following encoder:
implicit val intEntityEncoder: EntityEncoder[IO, Int] = jsonEncoderOf[IO, Int]
I thought that since IO[Int] encoder is declared, I can declare simply:
implicit val testEncoder: EntityEncoder[IO, List[IO[Int]]] = jsonEncoderOf[IO, List[IO[Int]]]
But it gives me error instead:
No given instance of type io.circe.Encoder[List[cats.effect.IO[Int]]] was found for an implicit parameter of method jsonEncoderOf in trait CirceInstances.
I found:
io.circe.Encoder.encodeIterable[cats.effect.IO[Int], List](
io.circe.Encoder.encodeIterable[Int, cats.effect.IO](
io.circe.Encoder.encodeInt
, /* missing */summon[cats.effect.IO[Int] => Iterable[Int]])
, ???)
But no implicit values were found that match type cats.effect.IO[Int] => Iterable[Int].
implicit val testEncoder: EntityEncoder[IO, List[IO[Int]]] = jsonEncoderOf[IO, List[IO[Int]]]