How to pass form content to Rest Service

19 views
Skip to first unread message

Krystian

unread,
Aug 11, 2014, 7:56:53 AM8/11/14
to lif...@googlegroups.com
Hi,
In my page I have form, which has dynamically changed number of lines. I'd like to pass content of this form to Rest service as a JSON. How to do that in Lift?

Thanks,
Krystian

Antonio Salazar Cardozo

unread,
Aug 11, 2014, 10:54:09 AM8/11/14
to lif...@googlegroups.com
Look into RestHelper—there are many examples both on the list and online. It will let you set up a REST
endpoint that will accept JSON that is automatically parsed by lift-json, at which point you can do whatever
you need with it.
Thanks,
Antonio

Krystian

unread,
Aug 11, 2014, 1:31:14 PM8/11/14
to lif...@googlegroups.com
Thanks,
But I need help with a way to pass content of form, to with writing rest helper.
In my snippet I have a form where number of rows might change (I'm just adding new rows by AppendHtml).
What I want to do is to somehow convert content of form to JSON and pass it to REST.

Diego Medina

unread,
Aug 11, 2014, 1:52:56 PM8/11/14
to Lift
you can do that with your favorite javascript library, jquery, etc. But maybe there is a better way to handle all this without using a rest endpoint.

maybe this post will help you

it adds fields to a page and send them all to the server, there is an example application with full code so you can play around with it and adjust it to fit your use case.

Hope it helps.

Diego







--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Diego Medina
Lift/Scala consultant
di...@fmpwizard.com
http://fmpwizard.telegr.am

Krystian

unread,
Aug 11, 2014, 2:08:51 PM8/11/14
to lif...@googlegroups.com
Thanks for hints. I'll play with it.

Regards,
Krystian

Krystian

unread,
Aug 11, 2014, 2:13:05 PM8/11/14
to lif...@googlegroups.com
Ok, I got it. I'll play with hints from your article as well.

Many thanks, Krystian

Antonio Salazar Cardozo

unread,
Aug 12, 2014, 9:50:25 AM8/12/14
to lif...@googlegroups.com
Rockin'. To address the core original question of “how do I take this form and turn it into JSON”—that is largely a client-side problem,
and while Lift provides helpers for various permutations of that, I don't think it makes sense for us to provide out-of-the-box helpers for
the particular use case you're describing (partly because you can handle it using strategies like Diego's).

Once you have your RestHelper set up, you can on the client always use jQuery to do something like:

  var formData = $('form').serializeArray()
  $.post('/path/to/rest/helper', formData, ...)

Another option is that you can just set your form's action to your RestHelper endpoint, and read the field values using S.param.

So, there are many strategies that lurk in the background here :)
Thanks,
Antonio
Reply all
Reply to author
Forward
0 new messages