我可以验证。
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"
)