Get Response body from play.api.mvc.Action[AnyContent] in Play framework (Scala)

playframework, scala

Solution

Rather than the manual result extraction vptheron describes, you can use `play.api.test.Helpers`:

import play.api.test.Helpers._
val result: Future[SimpleResult] = …
val bodyAsBytes: Array[Byte] = contentAsBytes(result)

There's also `contentAsString` etc.

Problem

I have the following Play (Scala) code: ``` object Experiment extends Controller { //routes file directs /genki here def genki(name: String) = Action(pipeline(name)) def pipeline(name: String) = { req:play.api.mvc.RequestHeader => { val template = views.html.genki(name) Experiment.Status(200).apply(template).as("text/html") } } def simple = Action { SimpleResult( header = ResponseHeader(200, Map(CONTENT_TYPE -> "text/plain")), body = Enumerator("Hello World!".getBytes()) ) } } ``` This compiles fine and works as expected. Using the scala REPL how can I display the actual html? I have: ``` scala> val action = simple action: play.api.mvc.Action[play.api.mvc.AnyContent] = Action(parser=BodyParser(anyContent)) ``` which I take to mean that now the value reference 'action' in the REPL is an Action object which is type-constrained for AnyContent (is that correct way to say it?). how can I now use this Action to print out the Http Response html content? Many thanks

Original source