[Lift] Re: How could i send a HTTP get or post request in the Snippet or Views in the Lift?
Well from your Snippet method you can just use HttpURLConnection, or Apache Commons Client to make remote requests to other services. Of course typically you won't do this directly from the snippet method but from a Service layer of your application. One you get the response (say it's an XML) you parse it using Scala XML class and the extract relevant information using pattern matching or by some other means. >From here you just construct the NodeSeq that the Snippet/View needs to return. As a side note ... If those requests are taking a long time, you can wrap your snippet in ... and it will be loaded asynchronously. There is another attribute (lift:parallel="true")that you could specify to a snippet that it will be run asynchronously allowing other snippets to process and the result will be merged into the HTTP response right before sending the response to the client. Note that you need to set LiftRules.allowParallelSnippets Br's, Marius On Dec 22, 8:39 am, "Neil.Lv" wrote: > Hi all, > > How could i send a HTTP get or post request in the Snippet or Views > in the Lift? > > For example, the weather API . > > I want to send an HTTP get request or post request to another > website that it supplies some > APIs, then in the lift we can receive the return data such as XML > data, so we can use these XML or Json data > in the Snippet or the Views. > > Thanks for any help! > > Cheers, > Neil -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
[Lift] Re: How could i send a HTTP get or post request in the Snippet or Views in the Lift?
You might want to checkout the scala http library, dispatch: http://databinder.net/dispatch/ Cheers, Tim On Dec 22, 7:46 am, Marius wrote: > Well from your Snippet method you can just use HttpURLConnection, or > Apache Commons Client to make remote requests to other services. Of > course typically you won't do this directly from the snippet method > but from a Service layer of your application. One you get the response > (say it's an XML) you parse it using Scala XML class and the extract > relevant information using pattern matching or by some other means. > From here you just construct the NodeSeq that the Snippet/View needs > to return. > > As a side note ... > If those requests are taking a long time, you can wrap your snippet in > ... and it will be loaded asynchronously. There is > another attribute (lift:parallel="true")that you could specify to a > snippet that it will be run asynchronously allowing other snippets to > process and the result will be merged into the HTTP response right > before sending the response to the client. Note that you need to set > LiftRules.allowParallelSnippets > > Br's, > Marius > > On Dec 22, 8:39 am, "Neil.Lv" wrote: > > > > > Hi all, > > > How could i send a HTTP get or post request in the Snippet or Views > > in the Lift? > > > For example, the weather API . > > > I want to send an HTTP get request or post request to another > > website that it supplies some > > APIs, then in the lift we can receive the return data such as XML > > data, so we can use these XML or Json data > > in the Snippet or the Views. > > > Thanks for any help! > > > Cheers, > > Neil -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
[Lift] Re: How could i send a HTTP get or post request in the Snippet or Views in the Lift?
Ok, Thanks guys! I'll be try it . Cheers. Neil On Dec 22, 4:36 pm, Timothy Perrett wrote: > You might want to checkout the scala http library, dispatch: > > http://databinder.net/dispatch/ > > Cheers, Tim > > On Dec 22, 7:46 am, Marius wrote: > > > Well from your Snippet method you can just use HttpURLConnection, or > > Apache Commons Client to make remote requests to other services. Of > > course typically you won't do this directly from the snippet method > > but from a Service layer of your application. One you get the response > > (say it's an XML) you parse it using Scala XML class and the extract > > relevant information using pattern matching or by some other means. > > From here you just construct the NodeSeq that the Snippet/View needs > > to return. > > > As a side note ... > > If those requests are taking a long time, you can wrap your snippet in > > ... and it will be loaded asynchronously. There is > > another attribute (lift:parallel="true")that you could specify to a > > snippet that it will be run asynchronously allowing other snippets to > > process and the result will be merged into the HTTP response right > > before sending the response to the client. Note that you need to set > > LiftRules.allowParallelSnippets > > > Br's, > > Marius > > > On Dec 22, 8:39 am, "Neil.Lv" wrote: > > > > Hi all, > > > >How could i send a HTTP get or post request in the Snippet or Views > > > in the Lift? > > > >For example, the weather API . > > > > I want to send an HTTP get request or post request to another > > > website that it supplies some > > > APIs, then in the lift we can receive the return data such as XML > > > data, so we can use these XML or Json data > > > in the Snippet or the Views. > > > > Thanks for any help! > > > > Cheers, > > > Neil -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.