Property Expansion in Responses

Applies to ReadyAPI 3.10, last modified on October 07, 2021

In ReadyAPI, you can include property values of your project, virtual service or data source in response contents:

  • You can include custom properties of your project or virtual service (that is, the properties that you can see on the Custom Properties page at the bottom of the Navigator panel), or

  • Any property of a data source that you associated with a response.

You specify properties by their names (see below). Before sending a response to a client, the virtual service expands the properties and replaces their references with actual property values.

Project and Service Properties

To refer to a property, use the following syntax:

${#MockService#property-name}

To refer to a project property, use the following syntax:

${#Project#property-name}

Just type the reference expression to the Edit box in response properties.

An easy way to insert a property reference is to use the Get Data command of the context menu: place the insertion point into the desired place within the Edit box, right-click and select Get Data > property-name from the context menu:

Service virtualization and API testing: The Get Data command

Click the image to enlarge it.

To refer to service and project properties in scripts, use code like this:

Groovy

// Service custom property
def propertyValue = requestContext.mockService.getPropertyValue('your-property-name')

// Project custom property
def propertyValue2 = requestContext.mockService.project.getProperty('your-property-name').getValue();

DataSource Properties

To refer to a data source property, use the following syntax:

${#MockResponse#datasource-property-name}

To refer to these properties from script, use code like this:

Groovy

def propertyValue = mockResponse.getPropertyValue('datasource-property-name')

Data source properties cannot be inserted with the Get Data command.

In order for a virtual service to expand these properties in a response, you need to specify the data source in the response’s DataSource property. See DataSources in Virtual Services for complete information.

See Also

Configuring Virtual Services
DataSources in Virtual Services
Property Expansion
Preparing Virtual Service Before Deploying to VirtServer

Highlight search results