New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need change response in runtime #120
Comments
+1 I had a similar scenario and created an ConditionalResponseHandler to handle it. The ConditionalResponseHandler holds a list with ConditionalResponses. For every request, it iterates through the list and selects the first wherein the condition is evaluated to true. Example:
Maybe a candiate for a Pull Request? Just a pity that Moco uses |
Can you provide me an example condition? I just wonder why you need a handler dispatcher rather than a request matcher. One more thing, Moco uses Guava which provides |
Hi @dreamhead I'm not sure if a request matcher can help for my case. But I am pretty sure you can tell me if so. I have an synchronization logic for two instances. The first instance tries to get information about a resource. Let’s do a HTTP GET /resource/1234. The remote instance (Moco) says HTTP 404 resource not found. An background synchronization task calls HTTP PUT to create the resource on the remote instance, I get an HTTP 201 created. The remote instance now knows the resource with the id 1234. So let’s try again a HTTP GET /resource/1234. The remote instance says HTTP 200 OK. My condition is, as long as I request GET /resource/1234 before the resource is synchronized, the remote instance should response with resource not found. After successfully creating the resource on the remote instance, the response should be HTTP OK. I also tried the SequenceHandler. But it depends on how fast the test itself and the background synchronization task runs to have more or less sequences. |
@hirtenfelder Thank you for your example. But I'd like to put this condition to matcher rather than response handler if I were you. httpServer.get(and(by(uri("/any/url"))), your_matcher1)).response(handler1);
httpServer.get(and(by(uri("/any/url"))), your_matcher2)).response(handler2); Personally, I prefer that Moco acts as a static server which means nothing will be changed at runtime. BTW, REST APIs will be published in a few days. |
Hi @dreamhead But my matchers are identical. There is no difference between the GET /resource/1234 before ( |
But Moco will compare the whole request matcher including |
Hi @dreamhead Thank you for your patience. I think now I understand. Of course, you’re right. Instead of using my This solution is much better. I try it and will show you the solution. |
@hirtenfelder Great! |
这是来自QQ邮箱的假期自动回复邮件。你好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。
|
In some scenarios, we need changing the response of an API in runtime.
I think there are 2 ways to achieve it.
I see below feature on plan page, does it mean the same thing?
The text was updated successfully, but these errors were encountered: