Wiremock API path url regex not working

2,292 views
Skip to first unread message

Abhijeet Ashri

unread,
Aug 6, 2020, 9:11:41 AM8/6/20
to wiremock-user
Hi Team,

So I have been trying to mock an API on my system for the URI format: "/v2/pet/aa"
What I have in my mappings.json is :

{
 
"request": {
 
"method": "GET",
 
"url": "/v2/pet/([0-9]*)"
 
},
 
"response": {
 
"status": 200,
 
"body": "<some-good-content>",
 
"headers": {
 
"Content-Type": "application/json"
 
}
 
}
 
}

I put ([0-9]*) to have only numerals coming as in the path variable.
I try hitting the URL - http://localhost:9999/v2/pet/11 , only to receive back the following.

                                               Request was not matched
                                               =======================

-----------------------------------------------------------------------------------------------------------------------
| Closest stub                                             | Request                                                  |
-----------------------------------------------------------------------------------------------------------------------
                                                           |
GET                                                        | GET
/v2/pet/([0-9]*)                                           | /v2/pet/11                                          <<<<< URL does not match
                                                           |
                                                           |
-----------------------------------------------------------------------------------------------------------------------

What I expected was a 200 HTTP Status along with the given body.
What is wrong with my configuration? Please correct me.

aaron...@willowtreeapps.com

unread,
Aug 6, 2020, 9:18:44 AM8/6/20
to wiremock-user
Check out the documentation on Url Matching.

If you want to match a url using regex, you'll need to use either "urlPattern" or "urlPathPattern"

Reply all
Reply to author
Forward
0 new messages