Support for TemplateResponseFileBody? #2350
-
|
With the update in #2163 FileBody is supported to allow complex response to be set externally. However there is no way to enable the body to support TemplateResponse? Thoughts on supporting this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Thanks for the suggestion — this is a great fit and it's now implemented on You actually get two complementary ways to combine external files with templating: 1. Template a {
"httpRequest": { "path": "/some/path" },
"httpResponse": {
"statusCode": 200,
"body": {
"type": "FILE",
"filePath": "responses/order.json",
"templateType": "MUSTACHE",
"contentType": "application/json"
}
}
}with { "method": "{{ request.method }}", "path": "{{ request.path }}" }Body-file templating supports the text engines MUSTACHE and VELOCITY (they render text directly). JavaScript templates build a full response object rather than a text fragment, so for JavaScript use the 2. Load a full template from a file — as a bonus, {
"httpRequest": { "path": "/some/path" },
"httpResponseTemplate": {
"templateType": "MUSTACHE",
"templateFile": "templates/some_response.mustache"
}
}If both Both are covered by unit tests and documented at Response Templates → Loading Templates From Files / Templating A Response Body File, and listed under the next release's changelog. It'll ship in the next release; until then it's available by building |
Beta Was this translation helpful? Give feedback.
Thanks for the suggestion — this is a great fit and it's now implemented on
master(commitbba4e4ea5).You actually get two complementary ways to combine external files with templating:
1. Template a
FILEresponse body — exactly what you asked for. A statichttpResponsewhose body is aFILEbody can now mark that file as a template with atemplateType. The file contents are rendered against the request before being returned, while the status code, headers and content type still come from the static response:{ "httpRequest": { "path": "/some/path" }, "httpResponse": { "statusCode": 200, "body": { "type": "FILE", "filePath": "responses/order.json", "templateType"