Skip to content

Instantly share code, notes, and snippets.

@henrikengstrom
Created February 19, 2012 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrikengstrom/1863329 to your computer and use it in GitHub Desktop.
Save henrikengstrom/1863329 to your computer and use it in GitHub Desktop.
play-mini HTTP POST
case POST(Path("/write")) ⇒ Action { implicit request =>
val start = System.nanoTime
val numberMonkeys = writeForm.bindFromRequest.get
AsyncResult {
(shakespeare ? numberMonkeys).mapTo[Result].asPromise.map { result ⇒
// We have a result - make some fancy pantsy presentation of it
val builder = new StringBuilder
builder.append("SHAKESPEARE WORDS:\n")
result.shakespeareMagic.foreach { w => builder.append(w + "\n") }
builder.append("UNWORTHY WORDS CREATED: " + result.unworthyWords.size + "\n")
builder.append("In " + (System.nanoTime - start)/1000 + "us\n")
Ok(builder.toString)
}
}
}
val writeForm = Form("number" -> number(min = 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment