The expression field in mocking can evaluate multiple fields:
To evaluate query or post parameters use the following syntax:request.params[parameter_name]=="parameter_value"
To evaluate a header use the following syntax:request.headers[‘header_name’]=="header_value"
You can string multiple queries together using standard Groovy expression language like below:
request.params[parameter_name]=="parameter_value"&&request.params[parameter_name]=="parameter_value"
request.headers[‘header_name’]=="header_value"||request.headers[‘header_name’]=="header_value"
To evaluate a POST body use the following syntax (this only works with JSON, so content type must be set to application/json):request.payload.”left_side_JSON”==”right_side_JSON”
You can also evaluate parts of the mocked url itself, if your mocked URL is https://m1-test.apif.apifortress.com/api/users/info
Starting after the “.com” you have “api”=0, “users”=1, “info”=2
Using the following syntax you can evaluate parts of the URL:request.pattern[1]==”users”
To note, the url can use wildcards like so:
https://m1-test.apif.apifortress.com/api/users/[a-zA-Z0-9]*
Which means the last part of the URL can be any string containing a lowercase, uppercase, or number. Then using the “request.pattern[2]” you can evaluate the last part.
It is to be noted that any manipulation needed in the expression field can be done using Groovy language.