From 1a9d3b183776aacd98aaf3c2dfd13d9b2f10fd35 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Wed, 15 Apr 2020 19:44:24 +0200 Subject: [PATCH] Updated Response Templating (markdown) --- Response-Templating.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Response-Templating.md b/Response-Templating.md index 09ab851..a693a02 100644 --- a/Response-Templating.md +++ b/Response-Templating.md @@ -63,18 +63,19 @@ The model of the request is supplied to the header and body templates. The follo * `request.body` - Request body text as string * `request.bodyAsJson` - Request body as dynamic Json Object. Note that the request **must** contain the header `Content-Type` with value `application/json`! -### Handlebars helpers -All of the standard helpers (template functions) provided by the [C# Handlebars implementation](https://github.com/rexm/Handlebars.Net) are available. - - ### Transform the content from a referenced file By default, only the response (headers, statuscode, body) are transformed when the `.WithTransformer()` or `UseTransformer` are defined. In case you also want to transform the contents from a referenced file (via `BodyAsFile`), an additional parameter need to added. Like `.WithTransformer(bool)` or `UseTransformerForBodyAsFile = true`. -### Generate Random Data Support +### Standard Handlebars helpers +All of the standard helpers (template functions) provided by the [C# Handlebars implementation](https://github.com/rexm/Handlebars.Net) are available. + +### Extra Handlebars helpers + +#### Generate Random Data Support It's possible to return random data using the `Random` Handlebars function. -#### Random Text +##### Random Text **Example**: to generate a random string between 8 and 20 characters, use this code in C#: ```csharp var server = WireMockServer.Start(); @@ -103,7 +104,7 @@ server ); ``` -#### Random (all supported randomizers) +##### Random (all supported randomizers) You can use the powerful Regular Expression string generator based on [Fare - Finite Automata and Regular Expressions](https://github.com/moodmosaic/Fare). - Text Regex Pattern: `"{{Xeger Pattern=\"[1-9][0-9]{3}[A-Z]{2}"}}"` @@ -125,14 +126,14 @@ Besides a random text string, it's also possible to generate this random data: Note: instead of using `\"` in above examples, you can also use `'`. -### JsonPath support +#### JsonPath support JsonPath support is also present (internal logic is based on Newtonsoft.Json). Two functions are present: 1. JsonPath.SelectToken 2. JsonPath.SelectTokens -#### JsonPath.SelectToken +##### JsonPath.SelectToken This can be used in C# like: ```csharp var server = WireMockServer.Start(); @@ -200,7 +201,7 @@ Note that also replacing values in a Json Object and returning a the body as Jso } ``` -### XPath support +#### XPath support XPath support is also present Three functions are present: @@ -208,7 +209,7 @@ Three functions are present: 2. XPath.SelectNodes 3. XPath.Evaluate -#### XPath.SelectSingleNode +##### XPath.SelectSingleNode This can be used in C# like: ```csharp var server = WireMockServer.Start();