I have created a simple routes:
class MyRoutes[F[_] : Async](service: MyService[F]) extends Http4sDsl[F] {
def routes: HttpRoutes[F] = HttpRoutes.of[F] {
case req@PUT -> Root / "bets" =>
for {
bet <- req.as[Bet]
created <- service.put(bet)
response <- Created(created)
} yield response
}
and a jsons implicits
for input and output:
object jsons {
implicit def circeDecoder[A[_] : Sync, B: Decoder]: EntityDecoder[A, B] = jsonOf[A, B]
implicit def circeEncoder[A[_] : Sync, B: Encoder]: EntityEncoder[A, B] = jsonEncoderOf[A, B]
}
But when I ran this program via Postman, I got an error:
The request body was invalid.
with 422
error code. I think it is something wrong with json encoder and decoder, because my request was very simple and clear:
{
"stake": 434,
"name": "Something"
}
I tried to add an implicit decoder into routes:
implicit val betDecoder: EntityDecoder[F, Bet] = jsonOf[F, Bet]
but it also did not help. Could anyone help me with that and tell how to create good encoder and decoder for jsons? I use circe
library for parsing.