Skip to content

Commit

Permalink
Fixed #459 and #719 - added the ability to combine standard and custo…
Browse files Browse the repository at this point in the history
…m matchers
  • Loading branch information
tomakehurst committed Nov 21, 2018
1 parent 4884971 commit 75a053b
Show file tree
Hide file tree
Showing 29 changed files with 1,507 additions and 935 deletions.
43 changes: 43 additions & 0 deletions docs-v2/_docs/extending-wiremock.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,49 @@ or via JSON:
}
```

### Combining standard and custom request matchers

An inline custom matcher can be used in combination with standard matchers in the following way:

```java
stubFor(get(urlPathMatching("/the/.*/one"))
.andMatching(new MyRequestMatcher()) // Will also accept a Java 8+ lambda
.willReturn(ok()));
```

Note that inline matchers of this form can only be used from Java, and only when `stubFor` is being called against a local
WireMock server. An exception will be thrown if attempting to use an inline custom matcher against a remote instance.


Custom matchers defined as extensions can also be combined with standard matchers.

Java:

```java
stubFor(get(urlPathMatching("/the/.*/one"))
.andMatching("path-contains-param", Parameters.one("path", "correct"))
.willReturn(ok()));
```

JSON:

```json
{
"request" : {
"urlPathPattern" : "/the/.*/one",
"method" : "GET",
"customMatcher" : {
"name" : "path-contains-param",
"parameters" : {
"path" : "correct"
}
}
},
"response" : {
"status" : 200
}
}
```

## Post-serve actions

Expand Down
Loading

0 comments on commit 75a053b

Please sign in to comment.