scala - 认证路由中的 http4s json 处理

标签 scala scala-cats circe http4s

我正在使用 Scala 3http4s 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/

相关文章:

scala - 将自定义谓词传递给 TableQuery 的过滤方法

scala - 在自由 monad 中使用 Either

scala - 在 Slick 和 Cats 中过滤和混合单子(monad)

json - 使用 Circe 将包含 HList 的案例类解析为 JSON 字符串

multithreading - 使用汇总的Scala并行频率计算不起作用

scala - SBT 在 Ubuntu 14.04 上使用 aptitude 安装失败

scala - 通用类型约束 ":<:"和 ":+:"在这个 Scala 示例中意味着什么?

scala - 如何在 Circe 中为 [Option[Option[A]] 编写自定义解码器?

json - 在 Scala 中使用选项 [ 或者 [A,B ] ] 解析 json 的替代方法

Scala Maven 构建错误 - scala.tools.nsc.typechecker.Typers