Scripts can be written using Groovy language and referenced inside resource files. The Console provides an editor for editing and saving Groovy script files.
Referencing Script files in Resources
Let's create a script file and save it with the name hello
as follows:
...
Here, we can observer that the values assigned to the response
array in the script are printed in the response output.
Executing functions
Groovy scripts can be used to create functions. Below is a simple factorial function example.
...
Code Block | ||||
---|---|---|---|---|
| ||||
{ "q": [ {"name":"Superman","rating":2,"id":1}, {"name":"Spiderman","rating":4,"id":2}, {"name":"Batman","rating":4,"id":5}, {"name":"I am legend","rating":5,"id":8} ], "greet": {"message":"Hello Batman"} } |
...
...
XRequest to Script
When integrating external APIs, scripts can help add additional processing. No need to upload projects or write extensive code. Formatting, conversion between APIs can be easily handled with scripting.
...