val req = FakeRequest("POST", "/user/test").withJsonBody(json)
package controllers
object User {
def create(username: String) = Action(parse.json) { req =>
// Do something
Ok(req.body)
}
}
POST /user/:username controllers.User.create(username)
"password" -> JsString("fakepassword")
)
val req = FakeRequest().copy(body = json)
val result = controllers.User.create("test")(req)
println(contentAsString(result))
status(result) must equalTo(OK)
val json = Json.obj(
"email" -> "test@example.com",
"password" -> "fakepassword"
)
--
--
val req = FakeRequest().copy(body = json)
This does not work for me in 2.1-RC1. The copy method is resolved to the one in RequestHeader and not to the one auto-generated by case class FakeRequest. What am I missing?
--
Hi Pascal,Can you please post an example of the corresponding Java way of doing your code snippet and Jame's above? Thanks!
--
Thanks Pascal! I was hoping for the nicer Scala API in Java as well...Are there any plans to "enrich" the Java JSON API like close to the Scala one?
--
val req = FakeRequest().withJsonBody(json).withHeaders(CONTENT_TYPE -> "application/json").copy(method = POST)
val result = await(controllers.ProfileApiV1.update(member1.getMemberIdString())(req).run)
But I still get this error:
bad request at: /, Invalid Json
I am using Play 2.1
val req = FakeRequest().withJsonBody(json).withHeaders(CONTENT_TYPE -> "application/json").copy(method = POST)