-
Notifications
You must be signed in to change notification settings - Fork 375
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
Allow response modifications in onAfterSuccess callback #225
Comments
Definitely an interesting feature that we hadn't considered before. I'll try to take a closer look at your branch, but right off the bat I can tell you that we would need to integrate this into the |
Thanks for considering it! I will certainly create a PR against the v2 branch. It is an important feature for us. Existing REST API resources are often extended. As long as the extension is not finished, developing a client needs a mock. But mocking the entire request would be inefficient; we'd like to mock minimally - just the missing features. |
+1 |
I would like to call the server, but modify the response to include additional data, before it is consumed by the caller. It helps the development, when the server API is only partially ready or when you want to test an alternative scenario, which would be not so easy to prepare on the server. I tried the
proxy
option:This way "almost" works, except for:
success
anderror
callbacks to update their model with the server response. If the server response needs to be modified before it reaches the model controller, the onAfter[X] have to be executed before the jQuery originals.I demonstrate this change in the propagate-callback-arguments branch.
Thinking further, the
proxy
option would work only for simple scenarios, allowing onlyurl
,type
anddata
passed to the proxy. Other options likeheaders
orcontentType
may be missing. I realized, that passing the request through to the server and updating the response may need more than the proxy offers. I introduced a newpassThrough
option, which makes the mocking simpler:I demonstrate this change in the passthrough-requests branch.
I got the "half-mocking" scenario, when the server responds, but the respond needs to be "massaged" a little before passed to the caller, working using the two changes above. Would you accept them into the official mockjax? Thanks!
The text was updated successfully, but these errors were encountered: