декодирование значения не является членом org.http4s.AuthedRequest

Я использую http4s версии 0.18 с Circe, и я получаю сообщение об ошибке value decode is not a member of org.http4s.AuthedRequest при преобразовании тела json в case class внутри AuthedService со следующим кодом:

  // 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 =>
          ...
        }
    }

person Valy Dia    schedule 27.02.2019    source источник


Ответы (1)


Оказывается, как указано в документации, AuthedService работает с AuthedRequest, что эквивалентно (User, Request[F]), поэтому необходимо вызвать decode в части request AuthedRequest, см.:

  // 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 =>
          ...
        }
    }
person Valy Dia    schedule 27.02.2019