Template
The following values are analyzed as a Groovy pattern:
Response header value
Response body (
body
)Response filename (
file
)Table key (
key
oftables
)
The following variables are available in a script block ${}
.
path
Path variables
headers
Request headers
params
Query parameters
query
Query parameters (alternative name for params
)
body
Request body
requestBody
Request body (alternative name for body
)
The request body type can be one of the following:
application/x-www-form-urlencoded
Map<String, String>
multipart/form-data
Map<String, Part>
application/json
and subset
Map<String, Object>
application/xml
and subset, text/xml
and subset
Map<String, Object>
text/*
String
Otherwise
null
For example, create a manifest as follows:
rules:
- request:
path: /users/{userId}
method: GET
response:
headers:
content-type: application/json
body:
id: ${path.userId},
name: User${path.userId}
The stub will return the following response on the request GET /users/100
:
{
"id": 100,
"name": "User100"
}
File templating
The files also support scripts
version: v1.1
rules:
- request:
path: /users/{userId}
method: POST
response:
headers:
content-type: application/json
file: big-dynamic-file.json
#big-dynamic-file.json
{
"id": "${path.userId}",
"name": "${requestBody.name}",
...
"account": "YU89RE00"
}
Last updated