Skip to main content

Expressions in Mocked APIs

Legacy Documentation
You're viewing legacy documentation for API Fortress (deployed via an on-premises container). To view documentation for the new SaaS version of API Fortress now known as Sauce Labs API Testing and Monitoring (with Sauce Connect tunnels) see API Testing on the Sauce Labs Cloud.


The expression field in mocking can evaluate multiple fields:

Evaluate a Query

To evaluate query or post parameters use the following syntax:

request.params[parameter_name] == 'parameter_value'

Evaluate a Header

To evaluate a header use the following syntax:


Multiple Queries

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'



Evaluate a POST body

To evaluate a POST body use the following syntax (this only works with JSON, so content type must be set to application/json):


Evaluate the URL

You can also evaluate parts of the mocked url itself, if your mocked URL is

Starting after the ".com" you have “api”=0, “users”=1, “info”=2

Using the following syntax you can evaluate parts of the URL:


Use Wildcards

The url can use wildcards like so:\[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.


Any manipulation needed in the expression field can be done using Groovy language.