Hi all I am looking for some guidance n best prac...
# help
r
Hi all I am looking for some guidance n best practices as well url/queryparams matchings. I have multiple end points all running on the same path so do you break these all up into smaller mappings files? And I am struggling with matches as with below this always comes back saying it cant be found.
Copy code
"request": {
        "method": "POST",
        "urlPath": "/domain/Patient",
        "queryParameters": {
          "identifier": {
             "matches": "<https://domain>\\.kemkes\\.go\\.id/id/nik(%7C|\\|)920401480400000[1-2]",
            "absent": false
          },
          "_count": {
            "equalTo": "1"
          },
          "name": {
            "absent": false
          },
          "birthdate": {
            "absent": false
          }
        }
      },
t
Hi Ross, it looks like you’re trying to match an entire URL in a single query parameter. Is your system actually passing entire URLs in the
identifier
query param? Also, you can only have one matcher expression per parameter unless you use the
AND
or
OR
combiners. In any case
"absent":false
is redundant when you also have the
matches
clause.
r
hi tom]
thanks for reaching out
the problem is the identifier is a URL query I have tried to use a simple contains or a match
and even just a contains * fails
is there a anywhere in teh docs that show cases the json and or? and what should I be using for this set up? it has to be an optional param
t
Could you provide a full example of a URL you’d like to match?
Also, are you definitely wanting to match query parameters with a POST request?
Most APIs use query with GET and the request body with POST
r
the thing is the same path returns the same result "https://fhir.kemkes.go.id/id/nik%7C9204014804000001" so the get and post return the same so then I can make thiis just work for a get started
this changes
}, "_count": { "equalTo": "1" }, "name": { "absent": false }, "birthdate": { "absent": false } these are optional but "identifier"is alwasy there
so I guess I could just focus on GET working
t
Can you share a full example request that you want to match? I think it’d be easier for me to make a recommendation if I can see the raw material.
t
OK, seems you’re requiring _count, name and birthdate but then they’re not present in the request URL. So that could be it.
r
its not complaining about those it complainign about the identifier
is there any docs that explain or help on this more? or a better way you would do this?
t
This is the main doc for this, but you’ve probably already found it: https://wiremock.org/docs/request-matching/#regular-expression
r
ok let me try that but I could nto get it to work before I just want any value that contains that URL
just this
conatins and mathces doesnt work
t
This works:
Copy code
{
  "request": {
    "method": "POST",
    "urlPath": "/fhir/Patient",
    "queryParameters": {
      "identifier": {
        "contains": "nik|9204014804000001"
      }
    }
  },
  "response": {
    "status": 200,
    "body": "Yes"
  }
}
r
why is the whoe URL not there?
t
Doesn’t need to be necessarily. If that ID number is enough to match the request uniquely, then there’s no point also including the URL part
r
ok will test this shortl;y thank you
t
This also works:
Copy code
{
  "request": {
    "method": "POST",
    "urlPath": "/fhir/Patient",
    "queryParameters": {
      "identifier": {
        "equalTo": "<https://fhir.kemkes.go.id/id/nik%7C9204014804000001>"
      }
    }
  },
  "response": {
    "status": 200,
    "body": "Yes"
  }
}
r
I cant use that as the end numbers may change
t
Copy code
{
  "request": {
    "method": "POST",
    "urlPath": "/fhir/Patient",
    "queryParameters": {
      "identifier": {
        "and": [
          {
            "contains": "<https://fhir.kemkes.go.id/id/nik%7C>"
          },
          {
            "contains": "920401480400000"
          }
        ]
      }
    }
  },
  "response": {
    "status": 200,
    "body": "Yes"
  }
}
r
thank you again nd will confirm its working
"contains": "920401480400000" this is the only dynamic part "contains": "920401480400001" "contains": "920401480400002"
would I not use an expression here?
plus isnt it all part of the same string so why the and and hte nested contains?
t
I’d assumed you wanted to match any ID that started with the first sequence of numbers and didn’t care about the last two. So
contains
would be fine in that situation. It is all part of the same string, I just find it more readable to break it up that way sometimes. Also, using regex matching where there’s also escaped URL characters can be quite hard to get right.
But that’s a matter of preference. If you really want to use
matches
there’ll be a way to make it work, but with a bit of regex wrangling.
r
I have tried MULTIPLE patterns even with a wildcard and it still fails to match
"matches": ".*(https://fhir\\.kemkes\\.go\\.id/id/nik|another-substring).*"
"identifier": { "matches": ".*fhir\\.kemkes\\.go\\.id.*nik.*920401480400000[1-2]" },
these all fail
so is there a better way to match this? even CONTAIN: https://fhir.kemkes.go.id/id/ fails
t
It worked for me
r
the ones I just gave you?
t
No, but I gave you a very similar one and it worked
r
but for my own education why would the examples I have given you be failing?
those seem to achieve the same result
t
This also works:
Copy code
"matches": "<https://fhir>\\.kemkes\\.go\\.id/id/nik\\|920401480400000[1-2]"
With this request URL:
Copy code
<http://localhost:3035/fhir/Patient?identifier=https%3A%2F%2Ffhir.kemkes.go.id%2Fid%2Fnik%7C9204014804000001>
r
ok Iw ill try replicate from postman