Updated Response Templating (markdown)

Stef Heyenrath
2020-01-09 18:09:29 +01:00
parent ca03d7c3d8
commit 66cd26d9ca

@@ -195,4 +195,53 @@ Note that also replacing values in a Json Object and returning a the body as Jso
}
}
}
```
```
### XPath support
XPath support is also present
Three functions are present:
1. XPath.SelectSingleNode
2. XPath.SelectNodes
3. XPath.Evaluate
#### XPath.SelectSingleNode
This can be used in C# like:
```csharp
var server = FluentMockServer.Start();
server
.Given(Request.Create().WithPath("/xpath1").UsingPost())
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/xml")
.WithBody("<response>{{XPath.SelectSingleNode request.body \"/todo-list/todo-item[1]\"}}</response>")
.WithTransformer()
);
```
Or using the admin mapping file:
``` js
{
"Request": {
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/xpath1"
}
]
},
"Methods": [
"post"
]
},
"Response": {
"Body": "<response>{{XPath.SelectSingleNode request.body \"/todo-list/todo-item[1]\"}}</response>",
"UseTransformer": true,
"Headers": {
"Content-Type": "application/xml"
}
}
}
```
For examples on `XPath.SelectNodes` and `XPath.Evaluate`, see https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsXPathTests.cs