Accessing the Body of a Post Request in a Groovy Script

Since the advent of 6.1.6 we've been able to access the body of a post in a Groovy script.  This frees us from the tyranny of those pesky predefined parameters and opens up all sorts of Javascript object-passing possibilities.

To keep this example as simple as possible, there are only two files:

postbody.html

TestPostBody.groovy

Check out a live demo at http://m2m.axeda.com/apps/TestPostBody/postbody.html .

 postbody.html

TestPostBody.groovy

The "body" variable is passed in as a standalone implicit object of type String.  The key here is that to process the string as a Json object in Groovy, we send stringified JSON from the Javascript, rather than the straight JSON object. 

FYI: If you happen to be using Scripto Editor (discussion http://developer.axeda.com/learn/by-type/technical-article/scripto-editor ), you might like to know that importing the Request class disables the sidebar input of parameters.  You can enter the parameters in the sidebar, but if this import is included the parameters will not be visible to the script.