Mock Server request matching - use request body as well

My question:
Is it possible to configure a Mock Server to also match by request body, not only by Url?
This is not mentioned in the docs, and I can confirm with the latest version, the differences in the bodies of two examples with the same Url are ignored.

Hi @a.f,

It sounds like what you’re looking for is the optional request header x-mock-match-request-body - if you send this with value true then the request body will be included in the comparison.

The header is mentioned very briefly in the documentation linked below:

Please let me know if it’s not functioning in the way that you’d hope, or if your problem is slightly different.

1 Like

@neilstudd Tahnk you!

It’s in the right direction, but it doesn’t work yet :slight_smile: . I’m getting “no matching request.”

This is the body I have defined in the example:

{
    "Prop1":"{{Prop1_Valid}}",
    "Prop2":"{{Prop2_Valid}}"
}

How is the body matched? binary wise, character wise or by parsing the json properties?
If it is matched binary or character wise, it will almost never match since the request will be dependent on the json serializer that I use.

I’m glad it’s getting you somewhere, although I think you’re now moving beyond the realms of my experience :smiley: Hopefully someone else can help to get you over the finish line!

Hi, @a.f did you manage to fix this?

I am in the same position now as @a.f was, does anyone know how to get the request body to match with an “example” body? Did you get anywhere @whiteshadow01 ?

It doesnt appear to work for me, I add the header, add a body and then add a body to the example (based on when I can see the mock server is saying I am sending)

Check the headers in your sample requests. In my case there were no headers configured, but the request included Content-Type: application/json and Accept: application/json .

Once I’ve added these headers in the samples and x-mock-match-request-body: true to the request, the matching did work!

Apparently x-mock-match-request-body: true also validates headers.