本教程展示了如何创建 http4s 请求:https ://http4s.org/v0.18/dsl/#testing-the-service
我想将此请求更改为 POST 方法并使用 circe 添加文字 json 正文。我尝试了以下代码:
val body = json"""{"hello":"world"}"""
val req = Request[IO](method = Method.POST, uri = Uri.uri("/"), body = body)
这给了我一个类型不匹配的错误:
[error] found : io.circe.Json
[error] required: org.http4s.EntityBody[cats.effect.IO]
[error] (which expands to) fs2.Stream[cats.effect.IO,Byte]
[error] val entity: EntityBody[IO] = body
我理解错误,但我不知道如何转换io.circe.Json
为EntityBody
. 我见过的大多数示例都使用EntityEncoder
,它不提供所需的类型。
我怎样才能转换io.circe.Json
成一个EntityBody
?