scalatra-website icon indicating copy to clipboard operation
scalatra-website copied to clipboard

Add `form-binder` doc

Open tminglei opened this issue 9 years ago • 2 comments

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!

tminglei avatar Feb 29 '16 05:02 tminglei

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?

rossabaker avatar Apr 14 '16 17:04 rossabaker

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.

tminglei avatar Apr 14 '16 22:04 tminglei