Created
April 16, 2015 01:56
-
-
Save hectorgool/77cebc16179678e8be8f to your computer and use it in GitHub Desktop.
Finagle client in Scala Play Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package controllers | |
| import play.api._ | |
| import play.api.mvc._ | |
| import lib._ | |
| import net.liftweb.json._ | |
| import play.api.libs.json.Json | |
| import scala.util.{Failure, Success} | |
| import play.api.libs.concurrent.Execution.Implicits.defaultContext | |
| import scala.concurrent.{Future, Promise} | |
| object ElasticSearch extends Controller { | |
| def index = Action { request => | |
| val json = request.body.asJson.get | |
| println(json) | |
| Ok | |
| } | |
| def alfa = Action.async(parse.json) { request => | |
| val p = Promise[Result] | |
| val response = FinagleClient.documentSearch(request.body ) | |
| val twitterFuture = response.map( rest => Ok("Got result: " + rest )) | |
| twitterFuture.onSuccess(p.success) | |
| twitterFuture.onFailure(p.failure) | |
| p.future | |
| } | |
| def beta = Action.async(parse.json) { request => | |
| val futureFinagle = FinagleClient.documentSearch( request.body ) | |
| val futureScala = TwitterConversions.twitter2Scala( futureFinagle) | |
| futureScala.map( f => Ok( "Got result: " + f ) ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment