Finch validationRule如何申请jsonBody?

时间:2018-03-20 22:55:54

标签: scala finch

我可以验证。

case class User(name: String, age: Int, email: String)

val mailRule = ValidationRule[String]("mail should be mailRule")("""(\w+)@([\w\.]+)""".r.unapplySeq(_).isDefined)

val child: Endpoint[User] = (
  param("name") ::
  param[Int]("age") ::
  param("email").should(mailRule) // ex testmail.com → I can receive the finchError 
).as[User

但是,我不知道在下面使用jsonBody [User]时验证是否适用。 请帮帮我。

val userJson:Endpoint[User] = jsonBody[User]
val createUserByJson: Endpoint[Int] = post("usersjson" :: userJson) { u: 
[User] =>
    ・・・
 }

我使用下面的库

libraryDependencies ++= Seq(
  "com.twitter" %% "finagle-mysql" % "18.3.0",
  "com.github.finagle" %% "finch-core" % "0.17.0",
  "com.github.finagle" %% "finch-argonaut" % "0.17.0",
  "com.twitter" %% "finagle-http" % "18.3.0",
  "com.github.finagle" %% "finch-circe" % "0.17.0",
  "io.circe" %% "circe-core" % "0.9.1",
  "io.circe" %% "circe-generic" % "0.9.1",
  "ch.qos.logback"  %  "logback-classic"  % "1.1.3"
)

0 个答案:

没有答案