I was wondering how to examine an HTTP request in Play Framework 2.1. The only information I can find on the documentation is via the conf/routes
mechanism:
GET /clients/:id controllers.Clients.show(id: Long)
but this will only allow us to get the parameter id
from the path. How do I access other part of the request, such as header or query params? In other words, what are Play's equivalents of JAX-RS @HeaderParam
, @FormParam
, @QueryParam
and such?
Within an action, you can get the request header using the request()
method, for instance, 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");
...
}