How to use wildcard in URL and querystring ?

3,616 views
Skip to first unread message

jayamurugan parasuraman

unread,
Dec 8, 2016, 9:24:17 AM12/8/16
to mountebank-discuss
Is there any possibility to use wildcard (like  "*") in the path ? So that we can use any dynamic values.
Ex: /customer/*/123   this should handle URL like  /customer/asdefr%2Fyyhl/123 and if it not matches with /customer/*/123 [highlighted part] it should not give the response.
*(asterisk)  should handle any type of value like  "asdefr%2Fyyhl". 

Brandon Byars

unread,
Dec 8, 2016, 9:44:41 AM12/8/16
to jayamurugan parasuraman, mountebank-discuss
Yes, but you have to use a regular expression syntax. ".*" (period-asterisk) represents anything (zero-or-more characters), or you could ensure that it's any character except the next forward slash with "[^/]+". It'd look like this:

"predicates":[
  {
    "matches": {
      "path": "/customer/[^/]+/123"
    }
  }
],
"responses": [...]

-Brandon

--
You received this message because you are subscribed to the Google Groups "mountebank-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mountebank-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jayamurugan parasuraman

unread,
Dec 9, 2016, 9:58:36 AM12/9/16
to mountebank-discuss, jayamur...@gmail.com
Thanks a lot for the quick response.
I have one more clarification here,
While using matches predicate in the path as you mentioned above  "path": "/customer/[^/]+/123" it is working even if we add extra path structure like this
/customer/qwerty/123/345/test .
or 
/customer/qwerty/12345678

But what we require is it should match exactly with path apart from the regex pattern part.

Here we tried predicate as "equals" but it looks like regex pattern not accepting in equals. Is there any limitation here ?
{
    "equals": {
      "path": "/customer/[^/]+/123"
    }

Kindly let me know if you have any solution.

Brandon Byars

unread,
Dec 9, 2016, 10:57:29 AM12/9/16
to jayamurugan parasuraman, mountebank-discuss
Sure. Regular expressions allow adding a $ to denote the end of string, so the regex would look like:

/customer/[^/]+/123$

-Brandon

To unsubscribe from this group and stop receiving emails from it, send an email to mountebank-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages