Hi everyone!
I am looking for a help as I am trying to provide different responses on same mock server calls. I tried with x-mock-response-name, x-mock-response-id and x-mock-match-request-headers but none of them are working on my system because I have not a classic “client-server” communication.
Let me explain my setup:
I have a client (let’s say local cURL or Postman), a middleware (an API I am developping) and a server (which I can’t edit at all). The server is the part I want to mock.
When the client requests the middleware, the middleware will trigger 2 different requests to the server (for instance, 1 for auth and 1 for the business logic) by transfering a white list of HTTP Headers I can control to the server.
What I want to do is:
- when the client requests the middleware with some custom header “Custom-Header: A”, the server (mocked) gives the responses
R1for the 1st request andR2_Afor the 2nd request. - when the client requests the middleware with some custom header “Custom-Header: B”, the server (mocked) gives the responses
R1for the 1st request andR2_Bfor the 2nd request.
My problem with x-mock-response-name and x-mock-response-id is that, even if I can set R2_A or R2_B, on client headers (so that the middleware will transfer them to the server for the second request), Postman gives me an error because when the 1st request is sent, only R1 is known so I have the mockResponseNotFoundError error.
I tried with x-mock-match-request-headers, but that’s basically the same issue: if on client side I am requesting the middleware with headers related to R1 and R2_A for instance, the 1st request is not having a matching headers as the response would only have the R1 header but not the R2_A.
Of course, even if I can control the white list of headers the middleware could transfer to the server, I cannot choose which headers are transfered for each request. The middle ware can only transfer to the server all the headers given that are matiching the whiltelist.
Is there any way to use something similar than x-mock-response-name, but if there are no responses matching with the given name, the default algorithm to select the example is executed rather than throwing an error? To me, this would be the easiest way to solve my situation.
Thank you a lot and please, do not hesitate to ask questions if I was unclear in my issue presentation ![]()
