I'm trying to mock query parameter using a wiremock JSON stub file.
It works when I do it this way :
{
"request": {
"method": "GET",
"url": "/posts?id=1",
},
//...
}
However when I change my query parameter to use the dedicated field like this it doesn't work anymore :
{
"request": {
"method": "GET",
"urlPath": "/posts",
"queryParameters": {
"id": {
"equalTo": "1"
}
}
},
//...
}
Any idea why ?
The test request looks like http://some-host/posts?id=1
This works for me, change your "urlPath" to "urlPathPattern" but be careful in structuring this JSON. so urlPath is exact matching pattern, but urlPathPattern is regex matching on path and query parameter
{
"request": {
"urlPathPattern": "/posts",
"method": "GET",
"queryParameters": {
"id": {
"equalTo": "1"
}
}
},
"response": {
"status": 200,
"body":"This is successful"
}
}
You can try with urlPathPattern instead of urlPath.
As said by here urlPath which is for an exact match, and urlPathPattern is for regex.
So using urlPathPattern in QueryParameter your query get resolve.
{
"request": {
"method": "GET",
"urlPathPattern": "/posts",
"queryParameters": {
"id": {
"equalTo": "1"
}
}
},
//...
}
Try and understand below concept for Wiremock.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With