Выяснить, какие значения представлены различными переменными шаблона ответа, не сложно.Ниже приведен пример для g
{
"request": {
"method": "GET",
"urlPathPattern": "/some/url/locales/en_GB/products",
"queryParameters": {
"typeName": {
"matches": "([A-Za-z]*)"
}
}
},
"response": {
"status": 200,
"body" : "request.requestline.pathSegments:\n[0]: {{request.requestLine.pathSegments.[0]}}\n[1]: {{request.requestLine.pathSegments.[1]}}\n[2]: {{request.requestLine.pathSegments.[2]}}\n[3]: {{request.requestLine.pathSegments.[3]}}\n[4]: {{request.requestLine.pathSegments.[4]}}\n[5]: {{request.requestLine.pathSegments.[5]}}\n\nrequest.query.typeName: {{request.query.typeName}}",
"transformers": [
"response-template"
]
}
}
И запрос GET http://localhost:8080/some/url/locales/en_GB/products?typeName=test
приводит к такому ответу:
request.requestline.pathSegments:
[0]: some
[1]: url
[2]: locales
[3]: en_GB
[4]: products
[5]:
request.query.typeName: test
С учетом вышесказанного вы можете видеть, что искомое значение равноне извлекается с помощью request.pathSegments[x]
, а request.query.typeName
.В результате получается:
{
"request": {
"method": "GET",
"urlPathPattern": "/some/url/locales/en_GB/products",
"queryParameters": {
"typeName": {
"matches": "([A-Za-z]*)"
}
}
},
"response": {
"status": 200,
"bodyFileName": "{{request.query.typeName}}.json",
"transformers": [
"response-template"
]
}
}