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