0

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.

User
  • 31,811
  • 40
  • 131
  • 232

1 Answers1

1

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

jcern
  • 7,798
  • 4
  • 39
  • 47
  • This gives: "could not find implicit value for parameter c: (Unit) => net.liftweb.http.LiftResponse" – User Dec 24 '12 at 18:48
  • I also tried: `S.request.foreach(x => x.paramNames.foreach(p => println(p) ) );` And shows compiler error in the println with message "scala is not an enclosing class" any idea...? – User Dec 24 '12 at 18:53
  • Ah... wait. I commented out the "Extraction.decompose(someList)" line, and it was trying to convert your code to LiftResponse. Give me a sec. – User Dec 24 '12 at 19:07
  • Yes, both errors were being caused by this. It works, although I'm not receiving any parameters :) but that's a different problem. – User Dec 24 '12 at 19:15