This message was deleted.
# general
s
This message was deleted.
a
So you only want to deem the request as a match if the body data matches the data in a separate request.xml file?
j
I want to give path for my request XML and path for my response XML (I am able to do that using the above code). I need to know how to give path for request XML file.
Yes if the request matched only then it should have response
Copy code
{
  "request": {
    "method": "GET",
    "url": "/body-file"
  },
  "response": {
    "status": 200,
    "bodyFileName": "path/to/myfile.xml"
  }
}
is there a way to add "bodyFileName" in the request
a
AFAIK, no -
bodyFileName
is only available to the response object. Usually, the requests would have something more specific than the entire request body that differentiate them. Are your request bodys unique in specific ways that you can tell one request from another without matching the entire body? JSON example:
Copy code
// request 1
{
  "id": 1234,
  ...
}
vs.
Copy code
// request 2
{
  "id": 0987,
  ...
}
j
Thanks. Just to understand. I am hardcoding the XML in the request as Body?
Copy code
{
    "request": {
        "method": "GET",
        "url": "/body-file"
        "body": "add the xml content here??"
    }
Are you referring to the above format?
a
It would be
bodyPatterns
, but I’m not suggesting hardcoding the entire body.
j
Sorry I am very new to Wiremock...do yu have the example pls
a
Do you have an example of two bodies, or more specifically, what you could use to say “oh, that should get response A” and “oh, that should get response B”
j
Example of request XML:
<?xml version="1.0"?> <customers> <customer id="55000"> <name>Charter Group</name> <address> <street>100 Main</street> <city>Framingham</city> <state>MA</state> <zip>01701</zip> </address> <address> <street>720 Prospect</street> <city>Framingham</city> <state>MA</state> <zip>01701</zip> </address> <address> <street>120 Ridge</street> <state>MA</state> <zip>01760</zip> </address> </customer> </customers>
how can I have a path or use this XML as an input in the request.
a
So, assuming that custom ID is the unique portion of the request body, you can use XPath matching. Rough guessing is something like this, but gimme a few and I can refine it
Copy code
{
  "request": {
    ...
    "bodyPatterns" : [ {
      "matchesXPath" : "/customers/customer/@id = \"55000\""
    } ]
    ...
  },
  ...
}
Don’t use a ton of XML/XPath, so a little rusty on it 😅
j
Thanks Aaron. I will give this a try. Thanks for your time.
a
Ok! I was a little off - something like this should work:
Copy code
"bodyPatterns": [
      {
        "matchesXPath": {
          "expression": "//customers/customer/@id",
          "equalTo": "55000"
        }
      }
    ]