Response Payload
This is where we create the main part of the response - the response body.
The payload can be pretty much any text format, with a natural preference for XML and JSON.
A binary response payload is hard to create at the moment - sorry.
The payload Content-Type header is defined in the Reaction Properties section and it should match the generated response.
XML Payload
XML payload is used for SOAP and XML services. Some content types that have XML as their base format, e.g. HTTP GET for WSDL, will also use XML payload.
Static XML Payload
To return a static XML payload, simply paste the payload into the payload field:
If the response is quite large, you can also upload it using the input field under the response text area.
Scripted XML Payload
Scripted XML payload is generated using XQuery.
The response XQuery has several variables available, including the request and its properties, mock accounts and meta information. See more about variables here.
Non-XML Payload (Likely JSON)
The response payload can generally be of any text format but the most commonly used is JSON.
The Content-Type of the response is defined in the Reaction Properties section and this controls how the payload will be interpreted by the client.
The response is sent back as UTF-8 by default and the Content-Type HTTP header is modified to include the charset
part:
Content-Type: application/json; charset=UTF-8
To use a different charset, provide the charset
part in the Content-Type property:
Static JSON Payload
Simply place static JSON payload into the response payload text area:
Note that in this case the content type should most likely be defined as application/json
.
Static Non-JSON Payload
A static non-JSON response should be defined as a Javascript string. For example, here the response is in the plain text but it is placed in quotes to form a valid Javascript string:
Scripted JSON Payload
A scripted JSON payload can be created by assigning scripted values to a JSON response payload:
Or, by assigning a Javascript object to the output
variable:
Scripted Non-JSON Payload
A scripted non-JSON response is still a result of a Javascript execution. You need to assign the desired result to the Javascript variable output
: