mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Path Variable id Not Working (ie. "/api/users/{id}")? #522
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @xayaraj on GitHub (Jun 22, 2023).
Originally assigned to: @StefH on GitHub.
Describe the bug
With the url /api/user/{id} endpoint where id is the path variable.
I have created the WireMock.Net server to listen for the given url path for Http incoming request.
Server:
_server
.Given(Request.Create().WithPath("/api/users/{id}").UsingGet())
.RespondWith(Response.Create().WithStatusCode(200).WithBody("User {id}"));
Client:
var client = new HttpClient();
var response = await client.GetAsync($"{_server.Urls[0]}/api/users/123");
var content = await response.Content.ReadAsStringAsync();
Response receive is 404 Not found
It might a simple stupid mistake or something that I have missed. Any help is appreciated. Thanks.
@StefH commented on GitHub (Jun 22, 2023):
The
{id}does not work, you can just use a wildcard string:/api/users/*. Can you try that ?@xayaraj commented on GitHub (Jun 23, 2023):
It works. Thank you.
Is there a way to retrieve the id which is 123 value and respond it back in the body as shown above?
@StefH commented on GitHub (Jun 23, 2023):
That would be possible using:
request.PathSegments.[<n>]--> URL path segment (zero indexed) e.g. request.PathSegments.[2]@xayaraj commented on GitHub (Jun 23, 2023):
Awesome. Thank you.