mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-10 03:13:53 +02:00
Updated Response Templating (markdown)
@@ -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.
|
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
|
```csharp
|
||||||
var server = WireMockServer.Start();
|
var server = WireMockServer.Start();
|
||||||
server
|
server
|
||||||
@@ -15,7 +19,7 @@ server
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
Mapping Json Example:
|
### Mapping Json Example using Handlebars.Net:
|
||||||
``` js
|
``` js
|
||||||
{
|
{
|
||||||
"Guid": "fd8ca21b-db82-48bc-ae5a-fc2153c2b0db",
|
"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 request model
|
||||||
The model of the request is supplied to the header and body templates. The following request attributes are available:
|
The model of the request is supplied to the header and body templates. The following request attributes are available:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user