This topic describes how to use a Groovy script to send an HTML response as a response of a virtual service.
Where to use
Use this script as a Script property of a response.
Example
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:
See Also
Virtual Service Scripting
Property Expansion
Groovy Scripting Samples
Scripting