Reputation: 5619
Hi In my playframework application I want to do a simple Post request.
So I defined in my Route this:
POST /printName @controllers.Index.printName()
Same way I do it in scala.
Then I have the following controller function:
public Result printName(Http.Request request) {
JsonNode json = request.body().asJson();
return ok("Got name: " + json.get("name").asText());
}
So now compiler returns:
missing arguments for method printName in class Index; follow this method with `_' if you want to treat it as a partially applied function
When I add the parameter in The route like this:
POST /printName @controllers.Index.printName(request: Request)
Then I got this error
not found: type Request
How would it be correct? Example is from Playframework page: https://www.playframework.com/documentation/2.7.x/JavaBodyParsers#The-default-body-parser
Thanks in advance.
Upvotes: 0
Views: 589
Reputation: 5619
I found the solution:
controller function
public Result printName() {
Http.Request request = request();
JsonNode json = request.body().asJson();
return ok("Got name: " + json.get("name").asText());
}
and the route
POST /printName @controllers.Index.printName()
Upvotes: 1