scalatra-website
scalatra-website copied to clipboard
Add `form-binder` doc
Hi,
Can I add form-binder's integration and usage doc into the guide?
Form-binder is a micro data binding and validating framework, very easy to use and hack.
With it, we can do data binding and validating very nice like this:
import com.github.tminglei.bind.simple._
class SampleServlet extends ScalatraServlet with MyFormBindSupport {
get("/:id") {
val mappings = tmapping(
"id" -> long(),
"body" -> (expendJson() >-: tmapping(
"email" -> text(required(), email()),
"price" -> (omitLeft("$") >-: float()),
"count" -> number().verifying(min(3), max(10))
))
)
binder.bind(mappings, data(multiParams)).fold(
errors => holt(400, errors),
{ case (id, (email, price, count)) =>
// do something here
}
)
}
...
Pls review and give your suggestion.
Thanks, Minglei Tu
p.s. I didn't run and check on my local, since rubygems.org was blocked in China, and I failed to install bundler and other related dependencies. So pls help run and check it. So sorry!
Wow, sorry, I missed the notification on this.
I'm open to this. It looks like an alternative to scalatra-commands, if I'm understanding it right?
Yeah, an alternative to scalatra-commands. I developed it initially for my scalatra project. Maybe also useful for other people. ^^
Can you help review and merge? Any suggestions pls let me know.