简体   繁体   中英

http4s json handling in authed routes

I am using Scala 3 and http4s 1.0.0-M35 . I want to use auth with json handling.

val routes = AuthedRoutes.of[User, IO] {
case request@POST -> Root / "dialog" / LongVar(dialogId) / "send" as user => {
      for {
        sendMessageRequest <- request.as[SendMessageRequest]

But got error

[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.

It suggests some imports:

[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

But after importing it, I have another error:

sendMessageRequest type is org.http4s.ContextRequest[cats.effect.IO, service.CreateDialogRequest]

How to use json handling in AuthedRoutes it?

I solved my problem. Just:

request.req.as

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM