Play Framework validates the HTTP request
I was wondering how to validate an HTTP request in Play Framework 2.1. The only information I can find in the documentation is the mechanism conf/routes
:
GET /clients/:id controllers.Clients.show(id: Long)
but this will allow us to get the parameter id
from the path. How can I access another part of the request, such as the header or request parameters? In other words, what are the equivalents of JAX-RS playback @HeaderParam
, @FormParam
, @QueryParam
and such?
source to share
Inside the activity, you can get the request header using a method request()
, for example in Java:
public static Result index() {
// example of a Header
String userAgent = request().getHeader("User-Agent");
// example of a query parameter
String q = request().getQueryString("q");
...
}
source to share