case GET(Path("/rtb_v1/bidrequest")) => Action { implicit request =>
I want to take the request object above and get all of the key/value pairs sent in the form post and flatten it into a Map[String,String]
i have gone through all the documents and am at a dead end.
This is pretty freaking easy in Java/Servlets I;m wondering why there is no documentation on a simple thing like this anywhere..
Map<String, String[]> parameters = request.getParameterMap();
To get all request parameters in java, we get all the request parameter names and store it in an Enumeration object. Our Enumeration object now contains all the parameter names of the request. We then iterate the enumeration and get the value of the request given the parameter name.
Request parameters are used to send additional information to the server. A URL contains these parameters. There are two types of parameters: Query Parameter: These are appended to the end of the request URL, Query parameters are appended to the end of the request URL, following '?'
For GET requests, input can be specified only as query parameters, because a GET request cannot have a body. This example shows a GET request on the search resource, with two query parameters in the query string.
Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.
Play's equivalent of request.getParamterMap
is request.queryString
, which returns a Map[String, Seq[String]]
. You can flatten it to a Map[String, String]
with
request.queryString.map { case (k,v) => k -> v.mkString }
And here is the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With