Scala – How to get payload from a POST in Play 2.0

playframework-2.0scala

I'm trying to implement a REST API with Play 2.0 (Scala) but I'm getting stuck in POST method. How do I get the payload from Request object? I haven't find any documentation about it and have been unable to figure out from source code.

Best Answer

You should be able to do the following:

def index = Action { request =>
  val body = request.body
}

And also things like:

def index = Action { request =>
  val name = request.queryString.get("name").flatMap(_.headOption)
  Ok("Hello " + name.getOrElse("Guest"))
}
Related Topic