Serving response based on string in request body

742 views
Skip to first unread message

Vishnu Vardhan

unread,
May 3, 2018, 7:51:39 PM5/3/18
to wiremock-user
Hi Tom,

Is there a way in where we can ask Wiremock to serve responses based on a string value present (or absent) in the request body? I understand that we can use the 'matchesXPath' parameter to validate for the presence of a node in a request body, but wanted to know if the search can be done with a "contains" function instead (for the entire request body)? So far my attempts at this have failed. My goal is to serve a particular response when a certain string is absent in the request body but I was not able to make much progress. Could you please help me out?

I apologize if a way is already mentioned in the Wiremock documentation - kindly point me to the right text if that is the case.

Regards,
Vishnu

Tom Akehurst

unread,
May 4, 2018, 4:52:04 AM5/4/18
to wiremock-user
I suggest taking a look at the doesNotMatch operator in http://wiremock.org/docs/request-matching/#regular-expression. That will match the request to the stub if the regex you in a non-match.

Vishnu Vardhan

unread,
May 4, 2018, 11:16:00 AM5/4/18
to wiremock-user
Thanks a lot, Tom! The 'doesNotMatch' operator did the job!

"bodyPatterns": [ {
        "doesNotMatch": ".*emailAddress.*"
    } ]

Regards,
Vishnu
Reply all
Reply to author
Forward
0 new messages