lecarpetron dookmarion
lecarpetron dookmarion

Reputation: 721

Wiremock matching path params

API Specs:

GET /customer/{{customerId}}

My Target responses:

  1. Input: "/customer/1234, Output: return 404 error
  2. Input: "/customer/(any value not equal to 1234): Output: 200 with return object

How do I set that any customerId path param not equal or equal to "1234" will have different outcomes?

Seems such a common scenario but I tried looking in this reference link below but can't find any

https://wiremock.org/docs/request-matching/

Upvotes: 1

Views: 3239

Answers (1)

agoff
agoff

Reputation: 7164

You can set up two separate mappings with different priorities, so that WireMock will check for the more specific ID first.

Here's an example where the more specific url has Priority 1, and the less specific url has Priority 2, meaning WireMock checks the more specific url first, and if it does not match, checks the less specific url.

{
  "mappings": [
    {
      "priority": 1,
      "request": {
        "url": "/customer/1234"
      },
      "response": {
        "status": 404
      }
    },
    {
      "priority": 2,
      "request": {
        "urlPath": "/customer/.*"
      },
        "response": {
            "status": 200,
            "bodyFileName": "customer.json"
        }
    }
  ]
}

Upvotes: 1

Related Questions