Skip to content

Request Matcher FormUrlEncodedMatcher

Stef Heyenrath edited this page Jul 27, 2024 · 2 revisions

FormUrlEncodedMatcher

Can be used to check if a Form Url Encoded body contains the key-value pairs.

C# option

var server = WireMockServer.Start();
server.Given(
    Request.Create()
        .UsingPost()
        .WithPath("/foo")
        .WithHeader("Content-Type", "application/x-www-form-urlencoded")
        .WithBody(new FormUrlEncodedMatcher(["name=John Snow", "[email protected]"]))
    )
    .RespondWith(
        Response.Create()
    );

JSON Mapping option

{
  "Request": {
    "Path": {
      "Matchers": [
        {
          "Name": "WildcardMatcher",
          "Pattern": "/foo"
        }
      ]
    },
    "Methods": [
      "POST"
    ],
    "Headers": [
      {
        "Name": "Content-Type",
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "application/x-www-form-urlencoded",
            "IgnoreCase": true
          }
        ]
      }
    ],
    "Body": {
      "Matcher": {
        "Name": "FormUrlEncodedMatcher",
        "Patterns": [
           "name=John Snow",
           "[email protected]"
         ],
        "IgnoreCase": true
      }
    }
  },
  "Response": {
    "StatusCode": 200
  }
}

📝 Notes

  • You can also use IgnoreCase
  • And you can also use wildcards like: name=John*
Clone this wiki locally