Applies to ReadyAPI 3.3.1, last modified on August 11, 2020

This topic describes how to use a Groovy script to send an HTML response as a response of a virtual service.

Availability

Use this script as a Script property of a response.

Example

The following code shows you how to send an HTML request and then use its response as a response of a virtual service:

Groovy

// Create a request
def get = new org.apache.http.client.methods.HttpGet( "https://smartbear.com" )

// Send the request
def response = org.apache.http.impl.client.HttpClients.createDefault().execute( get )

// Obtain the body of the response
def content = response.entity.content.text

// Save the body to a context property
context.content = content

Use the ${content} property expansion to insert the body of the HTML response to the body of the virtual API response:

Context propety expansion as a response body

Click the image to enlarge it.

See Also

Virtual Service Scripting
Property Expansion
Groovy Scripts

Highlight search results