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