value decode is not a member of org.http4s.AuthedRequest

299 Views Asked by At

I am using http4s version 0.18, with Circe and I am getting the error value decode is not a member of org.http4s.AuthedRequest when I converting the json body to a case class within an AuthedService with the following code:

  // case class definition
  case class UserUpdate(name: String)

  import org.http4s.AuthedService
  import org.http4s.circe._

  val updateUserService: AuthedService[String, F] =
    AuthedService {
      case req @ PATCH -> Root / "mypath" as _ =>
       req.decode[UserUpdate] { userUpdate =>
          ...
        }
    }
1

There are 1 best solutions below

0
On BEST ANSWER

It turns out that, as the documentation specifies, that AuthedService operates on AuthedRequest which is equivalent to (User, Request[F]), so what needs to be done is to call decode on the request part of the AuthedRequest, see:

  // case class definition
  case class UserUpdate(name: String)

  import org.http4s.AuthedService
  import org.http4s.circe._

  val updateUserService: AuthedService[String, F] =
    AuthedService {
      case authReq @ PATCH -> Root / "mypath" as _ =>
       authReq.req.decode[UserUpdate] { userUpdate =>
          ...
        }
    }