apimocker
apimocker copied to clipboard
accept callback function for user requests as a parameter for apimock
Hi @gstroup ,
I use apimock like this:
var ApiMocker = require("apimocker");
var apiMocker = ApiMocker.createServer(options)
.setConfigFile(__dirname + '/config.json')
.start(port, function() {/* callback for establish connection */});
Now I faced the task to use TimeStamp in responses because of the strict security restrictions of the .Net WCF library.
Is it possible to add response callback function to apimock?
+1
I think this is a good idea in general. @ztsmith suggested that it might be a better idea to expose the express middleware, then you could add a middleware function to do whatever you like. Would that solve your problem?? Let me know what you think.
Yes, that would solve my task. How do you think to expose the express middleware?
Please take a look at the latest version 0.4.9. I added support for custom middleware functions, that should solve this problem. Please let me know what you think! @tedvanderveen @asnov @ztsmith
Great! It is not so cute as to add a separate method to use chaining like this:
ApiMocker.createServer().setConfigFile().addmiddleware().start();
but it is works. It solves my task. Thank you!
Cool!
This makes me think.... if the config file was a JS file, we could define custom functions and middleware and specify them in the config. I think this would unlock an endless array of configuration options.
@asnov - yes, I thought of adding a simple "addMiddleware()" function, but I decided to expose the entire array. This way, people have full control over the order of middleware functions. But, it would probably make sense to add a simple "addMiddleware()" function as well.
@ztsmith - I was also thinking how it would be great to define custom functions right in the config file. But I wasn't sure how the config file would parse then... we'd need to do some more testing on that. But I like the idea.
@gstroup what is the status of this? Thanks!
@tedvanderveen At the moment, the entire "middlewares" array is exposed, so you can add a customer middleware function anywhere in the pipeline. https://github.com/gstroup/apimocker#adding-custom-middleware Does that meet your needs?
Or would you prefer to have a simple addMiddleware()
function instead? That would require a small code change.