C# - How to match a path with a wildcard in Wiremock.Net

In many cases you want some sort of wildcard in your URL matching for Wiremock.Net. Most REST URLs contain an id, especially at the end and often you need to mock this for your tests. This could be a GET or PUT request, for example on /person/{id}. Wiremock has support for this with the star symbol (*) being used as a wildcard, for example: /person/*. This can be seen in the example below using a GET request:

server
    .Given(
        Request.Create()
            .WithPath("/person/*")
            .UsingGet()
    )
    .RespondWith(
        Response.Create()
            .WithStatusCode(200)
            .WithBody(someBody) //Whatever you want to return for this request
    );

This will respond OK with a body on requests such as /person/1 or /person/f0b0346e-9900-4740-a84d-af2ebc3c28e5 using GET.

You can also have the wildcard in the middle of the URL if you want to use a wildcard for that part of the URL. This can be seen below:

server
    .Given(
        Request.Create()
            .WithPath("/person/*/2")
            .UsingPut()
    )
    .RespondWith(
        Response.Create()
            .WithStatusCode(200)
    );

This will respond OK on requests such as /person/1/2 or /person/f0b0346e-9900-4740-a84d-af2ebc3c28e5/2using PUT.

I hope the above makes sense, please let me know in the comments down below if this was helpful to you!