Updated Request Matching (markdown)

Stef Heyenrath
2019-05-04 09:58:01 +02:00
parent 4ce991e1c1
commit fbaf1fbe45

@@ -17,6 +17,7 @@ At this moment these matchers are supported:
* WildcardMatcher
* RegexMatcher
* XPathMatcher
* JmesPathMatcher
* JsonMatcher
* JsonPathMatcher
* SimMetricsMatcher
@@ -227,6 +228,62 @@ server
{ "things": { "name": "Wiremock" } }
```
### Jmes Path (JmesPathMatcher)
The JMESPath language is described in an ABNF grammar with a complete specification.
A JSON body will be considered to match a path expression if the expression returns either a non-null single value (string, integer etc.), or a non-empty object or array.
#### C#
```csharp
var server = FluentMockServer.Start();
server
.Given(
Request.Create().WithPath("/jmespath_example").UsingGet()
.WithBody(new JmesPathMatcher("things.name == 'RequiredThing"));
)
.RespondWith(Response.Create().WithBody("Hello"));
```
#### JSON Mapping
``` js
{
"Guid": "55a600b8-9d6f-453f-90c6-3db2b0885ddb",
"Request": {
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/jmespath_example",
"IgnoreCase": false
}
]
},
"Methods": [
"put"
],
"Body": {
"Matcher": {
"Name": "JmesPathMatcher",
"Pattern": "things.name == 'RequiredThing')]"
}
}
},
"Response": {
"StatusCode": 200,
"Body": "{ \"result\": \"JmesPathMatcher !!!\"}",
"UseTransformer": false
}
}
```
```
// matching
{ "things": { "name": "RequiredThing" } }
{ "things": [ { "name": "RequiredThing" }, { "name": "Wiremock" } ] }
// not matching
{ "price": 15 }
{ "things": { "name": "Wiremock" } }
```
### XPath
Deems a match if the attribute value is valid XML and matches the XPath expression supplied.
An XML document will be considered to match if any elements are returned by the XPath evaluation.
@@ -361,4 +418,4 @@ server
.RespondWith(Response.Create()
.WithStatusCode(HttpStatusCode.Unauthorized)
.WithBody(@"{ ""result"": ""api-key missing""}"));
```
```