mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-19 00:27:04 +01:00
Updated Response Templating (markdown)
@@ -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
|
||||
Reference in New Issue
Block a user