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
I had to do it somewhat differently (maybe I'm on a newer version of the codebase):
my javascript:
$(document).ready(function(){
$.post( "/ping", {one: "one", two: "two" },
function( data ){
console.log(data); //returns {"one":"one","two":"two"}
})
});
my route:
POST /ping controllers.Application.ping()
My controller method:
def ping() = Action{ request =>
val map : Map[String,Seq[String]] = request.body.asFormUrlEncoded.getOrElse(Map())
val one : Seq[String] = map.getOrElse("one", List[String]())
val two : Seq[String] = map.getOrElse("two", List[String]())
Ok(
toJson( JsObject(List( "one"->JsString(one.first), "two"->JsString(two.first))))
)
}
I assume this will change in the final version.