Question

I just want to examine the parameters sent in a REST request. I have seen methods like S.param("paramName"), or S.params("??"), but I just want to see all the parameters. How can I do it?

Have checked here: http://simply.liftweb.net/index-Chapter-11.html, and also many SO threads but finding only how to get certain parameters.

Edit Adding not working suggestions to the code

Edit2 Found the problem, I commented out the return value of the request :)

My current code:

object WebserviceHandler extends RestHelper {

    serve {
      case "somePath" :: Nil JsonPost _ =>

      //1st try
      for(s <- S.request; r <- s.params) { //compiler error: "could not find implicit value for parameter c: (Unit) => net.liftweb.http.LiftResponse"
        val (paramName:String, paramVals:List[String]) = r
      }

      //2nd try
      S.request.foreach(x => 
        x.paramNames.foreach(p => 
          println(p) //compiler error: "scala is not an enclosing class" 
        ) 
      );


      //Extraction.decompose(someList) //<--- Problem- this line was commented 

      //...
    }
}

Thanks in advance.

Was it helpful?

Solution

You can access them through the Req object. The code below will iterate through all the values and you can do what you need to with it.

for(s <- S.request; r <- s.params) {
    val (paramName:String, paramVals:List[String]) = r
}

If you just want the paramater names, you can use s.paramNames instead of s.params

Full api doc here: http://scala-tools.org/mvnsites/liftweb/lift-webkit/scaladocs/net/liftweb/http/Req.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top