diff --git a/Response-Templating.md b/Response-Templating.md index dfccb68..eb8f584 100644 --- a/Response-Templating.md +++ b/Response-Templating.md @@ -195,4 +195,53 @@ Note that also replacing values in a Json Object and returning a the body as Jso } } } -``` \ No newline at end of file +``` + +### 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("{{XPath.SelectSingleNode request.body \"/todo-list/todo-item[1]\"}}") + .WithTransformer() + ); +``` + +Or using the admin mapping file: +``` js +{ + "Request": { + "Path": { + "Matchers": [ + { + "Name": "WildcardMatcher", + "Pattern": "/xpath1" + } + ] + }, + "Methods": [ + "post" + ] + }, + "Response": { + "Body": "{{XPath.SelectSingleNode request.body \"/todo-list/todo-item[1]\"}}", + "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 \ No newline at end of file