Question

Documentation seems to be lacking on both the plugin side as well as the HTTPBuilder side of things. I'm trying to submit some json through the put method, but it keeps telling me that put() doesn't like the map I am feeding it.

Does anyone have an example of a PUT using the Grails REST Client plugin? Here is what I've tried:

withHttp(uri: "http://foo/doo/roo") {
        def bodyContent = [
            pano: jsonText
        ]

        def json = put(body: bodyContent)

        if (json.stat == 'ok') {
          wsr.success = true
        }
}

Error:

No signature of method: com.wbr.pano.PanService.put() is applicable for argument types: (java.util.LinkedHashMap) values: [[body:
    {
      "class":"com.wbr.platform.Pano",
      "errorMessage":"null",
      "imageSize":0,
      "id":26,
      "completed":"2011-03-20 3:50:27.257",
      "downloading":"2011-03-20 3:49:12.269",
      "processing":"2011-03-20 3:49:42.911",
      "uploading":"2011-03-20 3:50:12.107"
    }
  ]]
Was it helpful?

Solution

HTTPBuilder doesn't have a put method. Try changing withHttp to withRest so that your statements are executed with the RESTClient. Also, I think by default the body is encoded as URL encoded, so you might need to specify requestContentType: groovyx.net.http.ContentType.JSON as another parameter to your put.

import static groovyx.net.http.ContentType.*

withRest(uri: "http://foo/doo/roo") {
        def bodyContent = [
            pano: jsonText
        ]

        def json = put(body: bodyContent, requestContentType: JSON)

        if (json.status == 200) {
          wsr.success = true
        }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top