stubby4node
stubby4node copied to clipboard
[Admin] DELETE endpoint clear all stubs
Feature request: Be able to clear all stubs via Restful API
Why: It would be easy to clear all stubs and import a file with new requests
How: Change the DELETE endpoint to allow be called to the root URL or give a new URL ("/all") to wipe out the stubs
Please comment because I plan to fork this project and submit a PR
This seems like a good feature request!
I have been honestly very busy recently and probably won't have time for a while. I am willing to review any PR you send though
This has been around for a while! haha.
I'm keen for this feature. I tried to implement it without having to modify stubby but I couldn't since when you create a new stub, the ID isn't returned :(
So I'm going to have to modify Stubby.
I'll give it a go today and submit a PR when I can.
Actually; I see that the ID of a newly created stub is returned within the Location
header.
I also noticed that within the delete
method, if you pass a callback and no id
, it will reset the stub data. eg.
Stubby.prototype.delete = function (id, callback) {
var self = this;
if (id == null) { id = noop; }
if (callback == null) { callback = id; }
setTimeout(function () {
if (typeof id === 'function') {
self.endpoints.deleteAll(callback);
} else {
self.endpoints.delete(id, callback);
}
}, 1);
};
Currently the http DELETE
method requires an id
be passed eg.:
Admin.prototype.goDELETE = function (request, response) {
var id = this.getId(request.url);
var self = this;
if (!id) { return this.notSupported(response); }
function callback (err) {
if (err) { self.notFound(response); } else { self.noContent(response); }
}
this.endpoints.delete(id, callback);
};
So I could just change that method to allow no ID, and that would result in deleting everything? eg.
DELETE http://localhost:8083
instead of DELETE http://localhost:8083/:id