diff --git a/_docs/request-matching.md b/_docs/request-matching.md index 7e59de01..58795547 100644 --- a/_docs/request-matching.md +++ b/_docs/request-matching.md @@ -8,21 +8,22 @@ description: WireMock supports matching of requests to stubs and verification qu WireMock enables flexible definition of a [mock API](/) by supporting rich matching of incoming requests. Stub matching and verification queries can use the following request attributes: -- URL -- HTTP Method -- Query parameters -- Form parameters -- Headers -- Basic authentication (a special case of header matching) -- Cookies -- Request body -- Multipart/form-data +- URL +- HTTP Method +- Query parameters +- Form parameters +- Headers +- Basic authentication (a special case of header matching) +- Cookies +- Request body +- Multipart/form-data Here's an example showing all attributes being matched using WireMock's in-built match operators. It is also possible to write [custom matching logic](../extending-wiremock#custom-request-matchers) if you need more precise control: ## Request with XML Body -Java: + +Code: ```java stubFor(any(urlPathEqualTo("/everything")) @@ -41,7 +42,7 @@ stubFor(any(urlPathEqualTo("/everything")) .willReturn(aResponse())); ``` -JSON: +Configuration file: ```json { @@ -126,7 +127,6 @@ stubFor(post(urlPathEqualTo("/mock")) } ``` - The following sections describe each type of matching strategy in detail. ## URL matching @@ -664,7 +664,7 @@ JSON: Request body example: -``` +```json // matching { "things": { "name": "RequiredThing" } } { "things": [ { "name": "Required" }, { "name": "Wiremock" } ] } @@ -701,7 +701,7 @@ JSON: Request body example: -``` +```json // matching { "things": [ { "name": "RequiredThing" }, { "name": "Wiremock" } ] } // not matching @@ -1340,14 +1340,14 @@ JSON:
The full list of available truncations is: -- `first minute of hour` -- `first hour of day` -- `first day of month` -- `first day of next month` -- `last day of month` -- `first day of year` -- `first day of next year` -- `last day of year` +- `first minute of hour` +- `first hour of day` +- `first day of month` +- `first day of next month` +- `last day of month` +- `first day of year` +- `first day of next year` +- `last day of year` ## Logical AND and OR @@ -1487,7 +1487,6 @@ This would match the following JSON request body: } ``` - ### Matching Header/Query parameter containing multiple values You can match multiple values of a query parameter or header with below provided matchers. @@ -1501,7 +1500,7 @@ stubFor(get(urlPathEqualTo("/things")) .willReturn(ok())); ``` -```json +```json { "mapping": { "request" : { @@ -1607,7 +1606,6 @@ stubFor(get(urlPathEqualTo("/things")) } ``` - ```java //values of id must conform to the match expressions stubFor(get(urlPathEqualTo("/things")) @@ -1617,6 +1615,7 @@ stubFor(get(urlPathEqualTo("/things")) notContaining("3") )).willReturn(ok())); ``` + ```json { "mapping": { @@ -1644,4 +1643,4 @@ stubFor(get(urlPathEqualTo("/things")) } } } -``` \ No newline at end of file +``` diff --git a/_docs/stubbing.md b/_docs/stubbing.md index 90a9c8bb..6d4fe204 100644 --- a/_docs/stubbing.md +++ b/_docs/stubbing.md @@ -12,11 +12,44 @@ responses for requests matching criteria. These are described in detail in [Requ ## Basic stubbing -The following code will configure a response with a status of 200 to be -returned when the relative URL exactly matches `/some/thing` (including -query parameters). The body of the response will be "Hello world!" and a +You can configure stubs using JSON configuration files or code: + +1. Via a `.json` file under the `mappings` directory +2. Via a POST request to +`http://