我正在使用 Scala 3
和 http4s 1.0.0-M35
。我想将 auth 与 json 处理结合使用。
val routes = AuthedRoutes.of[User, IO] {
case request@POST -> Root / "dialog" / LongVar(dialogId) / "send" as user => {
for {
sendMessageRequest <- request.as[SendMessageRequest]
但出现错误
[error] | sendMessageRequest <- request.as[SendMessageRequest]
[error] | ^^^^^^^^^^
[error] |value as is not a member of org.http4s.ContextRequest[cats.effect.IO, repository.User], but could be made available as an extension method.
它建议一些导入:
[error] |One of the following imports might fix the problem:
[error] |
[error] | import cats.Functor.nonInheritedOps.toFunctorOps
[error] | import cats.Functor.ops.toAllFunctorOps
[error] | import cats.NonEmptyTraverse.ops.toAllNonEmptyTraverseOps
[error] | import cats.Traverse.ops.toAllTraverseOps
[error] | import cats.implicits.toFunctorOps
[error] | import cats.syntax.all.toFunctorOps
[error] | import cats.syntax.functor.toFunctorOps
但是导入后,又出现了一个错误:
sendMessageRequest
类型为 org.http4s.ContextRequest[cats.effect.IO, service.CreateDialogRequest]
如何在AuthedRoutes中使用json处理呢?
最佳答案
我解决了我的问题。只是:
request.req.as
关于scala - 认证路由中的 http4s json 处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73296731/