Andrez Segovia

Form Param Request Matching with WireMock

Published on • • 51 Words

The following is an example of how to use the withFormParam method to customize the response of a stub based on the value of a from parameter.

1WireMock.stubFor(post(urlEqualTo("/my-endpoint"))
2	.withHeader("Content-Type", containing("application/x-www-form-urlencoded"))
3	.withFormParam("field1", equalTo("value1"))
4	.willReturn(aResponse()
5		.withStatus(200)
6		.withBody("Response for field1=value1")));

The withFormParam method was implemented in WireMock 3.0.0 release.