mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-18 07:00:04 +02:00
Updated Request Matching (markdown)
@@ -17,6 +17,7 @@ At this moment these matchers are supported:
|
|||||||
* WildcardMatcher
|
* WildcardMatcher
|
||||||
* RegexMatcher
|
* RegexMatcher
|
||||||
* XPathMatcher
|
* XPathMatcher
|
||||||
|
* JmesPathMatcher
|
||||||
* JsonMatcher
|
* JsonMatcher
|
||||||
* JsonPathMatcher
|
* JsonPathMatcher
|
||||||
* SimMetricsMatcher
|
* SimMetricsMatcher
|
||||||
@@ -227,6 +228,62 @@ server
|
|||||||
{ "things": { "name": "Wiremock" } }
|
{ "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
|
### XPath
|
||||||
Deems a match if the attribute value is valid XML and matches the XPath expression supplied.
|
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.
|
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()
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(HttpStatusCode.Unauthorized)
|
.WithStatusCode(HttpStatusCode.Unauthorized)
|
||||||
.WithBody(@"{ ""result"": ""api-key missing""}"));
|
.WithBody(@"{ ""result"": ""api-key missing""}"));
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user