Sofiane Benamour
Sofiane Benamour

Reputation: 13

How to pass an array in Wiremock query parameters

It is couple days now, i'm stuck with Wiremock. I cannot figure out how to send an array parameters in GET method. i want to send this GET http://localhost/test?filter[]=full&token=any. so my json look like that

{
    "request": {
        "method": "GET",
        "urlPath": "/test?filter[]=full",
        "queryParameters": {
             "token": {
                 "matches": "^[A-Za-z0-9-_=.]*$"
             }
        }
    },
    "response": {
        "status": 200
    }
}

but i got an error, here the error response

| Closest stub                                             | Request                                                  |
-----------------------------------------------------------------------------------------------------------------------
                                                           |
GET                                                        | GET
/test?filter[]=full                                        | /test?filter[]=full&token=eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp<<<<< URL does not match
                                                           | XVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rU
                                                           | YAOvfzdceoH48wgRQ
                                                           |
Query: token [matches] ^[A-Za-z0-9-_=.]*$                  | token:
                                                           | eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkw
                                                           | MjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ
                                                           |
                                                           |
-----------------------------------------------------------------------------------------------------------------------

so if anyone know how to send an array parameter with a GET method, i will appreciated.

Thanks

Upvotes: 1

Views: 3012

Answers (1)

Tom
Tom

Reputation: 4149

The problem is that you're putting a query parameter in the URL path:

"urlPath": "/test?filter[]=full"

What you need to do is move filter[] into the query parameters block:

{
  "request": {
    "method": "GET",
    "urlPath": "/test",
    "queryParameters": {
      "token": {
        "matches": "^[A-Za-z0-9-_=.]*$"
      },
      "filter%5B%5D": {
        "equalTo": "full"
      }
    }
  },
  "response": {
    "status": 200
  }
}

Upvotes: 1

Related Questions