While stubbing with same request uri, with different response codes, how to call the endpoints #421

Closed
opened 2025-12-29 08:27:57 +01:00 by adam · 2 comments
Owner

Originally created by @bhargavjulaganti on GitHub (Jun 10, 2022).

I have a requirement, where my request url is same, but I need to respond back with different http response codes.

Here is the sample code


       var wireMockServer = WireMockServer.Start(63990);
        
        wireMockServer
            .Given(
                Request.Create()
                    .WithPath("/test")
                    .UsingGet()
            )
            .WithGuid("96754b07-7baf-4437-bebd-8aaf31ecfe15")
            .RespondWith(Response.Create().WithStatusCode(200));
        
        wireMockServer
            .Given(
                Request.Create()
                    .WithPath("/test")
                    .UsingGet()
            )
            .WithGuid("9c521fe0-57be-4f8a-ad91-800ef3f27499")
            .RespondWith(Response.Create().WithStatusCode(500));


How can I get different response codes based on the guid ? 
Originally created by @bhargavjulaganti on GitHub (Jun 10, 2022). I have a requirement, where my request url is same, but I need to respond back with different http response codes. Here is the sample code ```cs var wireMockServer = WireMockServer.Start(63990); wireMockServer .Given( Request.Create() .WithPath("/test") .UsingGet() ) .WithGuid("96754b07-7baf-4437-bebd-8aaf31ecfe15") .RespondWith(Response.Create().WithStatusCode(200)); wireMockServer .Given( Request.Create() .WithPath("/test") .UsingGet() ) .WithGuid("9c521fe0-57be-4f8a-ad91-800ef3f27499") .RespondWith(Response.Create().WithStatusCode(500)); How can I get different response codes based on the guid ?
adam added the question label 2025-12-29 08:27:57 +01:00
adam closed this issue 2025-12-29 08:27:58 +01:00
Author
Owner

@StefH commented on GitHub (Jun 10, 2022):

That guid is just an identification for the mapping. So that you can delete/update that specific mapping via the admin interface.

This guid is not used when matching the request.

You need to make sure that call your request application makes is different, else WireMock.Net cannot know which one to return. (Example : you can add an extra query or header parameter to make the difference)

An other possibility is that you define a scenario (https://github.com/WireMock-Net/WireMock.Net/wiki/Scenarios-and-States):

  1. return 200 the first time
  2. return 500 the second time
@StefH commented on GitHub (Jun 10, 2022): That `guid` is just an identification for the mapping. So that you can delete/update that specific mapping via the admin interface. This guid is not used when matching the request. You need to make sure that call your request application makes is different, else WireMock.Net cannot know which one to return. (Example : you can add an extra query or header parameter to make the difference) An other possibility is that you define a scenario (https://github.com/WireMock-Net/WireMock.Net/wiki/Scenarios-and-States): 1. return 200 the first time 2. return 500 the second time
Author
Owner

@bhargavjulaganti commented on GitHub (Jun 10, 2022):

Thanks for the update.

@bhargavjulaganti commented on GitHub (Jun 10, 2022): Thanks for the update.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#421