https://linen.dev logo
Title
o

Omkar Goulay

02/17/2023, 6:26 AM
Hi, Is there a documentation on stubbing
application/x-www-form-urlencoded
request?
r

Rob Elliot

02/17/2023, 9:34 AM
What is it you need to do? You can match on the
Content-Type
header & the body:
stubFor(
  get(urlEqualTo("/some/thing"))
    .withHeader("Content-Type", equalTo("application/x-www-form-urlencoded"))
    .withRequestBody(containing("foo=bar"))
    .willReturn(aResponse())
);
If you need to use the values in the response have a look at "Form helper" under https://wiremock.org/docs/response-templating/ .
There aren't any form specific matchers but it might be nice to add them - something like:
.withRequestBody(
  matchingFormKey("foo", equalTo("bar))
)
You could have a look at
MatchesJsonPathPattern
as an example of how to do it.