Send HTML Response From Virtual API

Applies to ReadyAPI 3.57, last modified on December 20, 2024

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:

Context propety expansion as a response body

Click the image to enlarge it.

See Also

Virtual Service Scripting
Property Expansion
Groovy Scripting Samples
Scripting

Highlight search results