Matching Path withe route parameter ? #470

Closed
opened 2025-12-29 15:24:37 +01:00 by adam · 2 comments
Owner

Originally created by @mehdihadeli on GitHub (Nov 25, 2022).

Hi,
I have a get endpoint with a route parameter id, how can I setup wiremock for accepting requested ID in my route and send corresponding response based on id?

GET
/people/{id}
Originally created by @mehdihadeli on GitHub (Nov 25, 2022). Hi, I have a get endpoint with a route parameter `id`, how can I setup wiremock for accepting requested ID in my route and send corresponding response based on id? ``` cmd GET /people/{id} ```
adam added the question label 2025-12-29 15:24:37 +01:00
adam closed this issue 2025-12-29 15:24:37 +01:00
Author
Owner

@StefH commented on GitHub (Nov 26, 2022):

In case you use json mapping, use this for the path request matching:

using :

  • RegexMatcher (example below)
  • Or Wildcard (example : /people/*)
{
    "Guid": "70000000-a633-40e8-a244-5cb80b700001",
    "Request": {
        "Path": {
            "Matchers": [
                {
                    "Name": "RegexMatcher",
                    "Pattern": "^/people/[0-9]{4}"
                }
            ]
        },
        "Methods": [
            "get"
        ]
    },
    "Response": {
        "Body": "OK",
        "UseTransformer": true,
        "Headers": {
            "Content-Type": "application/json"
        }
    }
}

or
C# example:
Wildcard matcher example:

server
                .Given(Request.Create()
                    .UsingGet()
                    .WithPath("/path/*")
                )
@StefH commented on GitHub (Nov 26, 2022): In case you use json mapping, use this for the path request matching: using : - RegexMatcher (example below) - Or Wildcard (example : `/people/*`) ``` json { "Guid": "70000000-a633-40e8-a244-5cb80b700001", "Request": { "Path": { "Matchers": [ { "Name": "RegexMatcher", "Pattern": "^/people/[0-9]{4}" } ] }, "Methods": [ "get" ] }, "Response": { "Body": "OK", "UseTransformer": true, "Headers": { "Content-Type": "application/json" } } } ``` or C# example: Wildcard matcher example: ``` c# server .Given(Request.Create() .UsingGet() .WithPath("/path/*") ) ```
Author
Owner

@mehdihadeli commented on GitHub (Nov 26, 2022):

@StefH Thanks

@mehdihadeli commented on GitHub (Nov 26, 2022): @StefH Thanks
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#470