Skip to content

Instantly share code, notes, and snippets.

@mwylde
Created January 31, 2014 01:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwylde/8724700 to your computer and use it in GitHub Desktop.
Save mwylde/8724700 to your computer and use it in GitHub Desktop.
override def query(q: String) = {
import net.liftweb.json._
import net.liftweb.json.JsonDSL._
import net.liftweb.json.Serialization.{read, write}
implicit val formats = DefaultFormats
val futures = clients.map(_.query(q).map(hr => {
val list = (parse(hr.getContent.toString("UTF-8")) \ "results").children
list.map(_.extract[String])
}))
Future.collect(futures).map(responses => {
val json = ("success" -> true) ~ ("results" -> responses.flatten.toList)
val response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)
response.setContent(copiedBuffer(compact(render(json)), UTF_8))
response
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment