Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all request parameters in Play and Scala

 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();
like image 230
Ryan Medlin Avatar asked Nov 13 '12 04:11

Ryan Medlin


People also ask

How do I get all request parameters?

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.

How do you request parameters?

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 '?'

Can a get request have query parameters?

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.

What are request query parameters?

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.


1 Answers

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.

like image 151
Kim Stebel Avatar answered Sep 23 '22 19:09

Kim Stebel