Updated Response Templating (markdown)

Stef Heyenrath
2021-01-20 08:08:16 +01:00
parent d848d77d2f
commit a3fd130480

@@ -1,7 +1,11 @@
Response headers and bodies can optionally be rendered using [Handlebars.Net](https://github.com/rexm/Handlebars.Net) templates.
Response headers and bodies can optionally be rendered using
- [Handlebars.Net](https://github.com/rexm/Handlebars.Net) templates.
- [Scriban/Scriban DotLiquid](https://github.com/scriban/scriban)
This enables attributes of the request to be used in generating the response e.g. to pass the value of a request ID header as a response header or render an identifier from part of the URL in the response body. To use this functionality, add `.WithTransformer()` to the response builder.
C# Example:
### C# Example for using Handlebars.Net :
```csharp
var server = WireMockServer.Start();
server
@@ -15,7 +19,7 @@ server
);
```
Mapping Json Example:
### Mapping Json Example using Handlebars.Net:
``` js
{
"Guid": "fd8ca21b-db82-48bc-ae5a-fc2153c2b0db",
@@ -40,6 +44,34 @@ Mapping Json Example:
}
```
### Scriban
For using Scriban as templating engine, just provide the type:
#### C#
``` c#
// . . .
.WithTransformer(TransformerType.Scriban) // or TransformerType.ScribanDotLiquid
// . . .
```
#### JSON
``` js
{
. . .
"Response": {
. . .
"UseTransformer": true,
"TransformerType": "Scriban"
}
}
```
# Note
Scriban and Handlebars.Net are supported, however some functionality from Scriban cannot not (yet) be used in WireMock.Net, these topics are:
- DOT notation for accessing this {{request.PathSegments.[0]}} does not work
- WireMockList is not supported by Scriban
So the examples and explication below is mostly targeted to Handlebars.Net
# The request model
The model of the request is supplied to the header and body templates. The following request attributes are available: