Request: add top level DELETE route
toratora opened this issue · comments
Fantastic plugin! Using it to generate all my REST routes. What's missing is a delete_all method to delete all elements under a route instead of just one specific element.
To use an example from your POD:
#
# Pattern Methods Name Class::Method Name
# ------- ------- ---- ------------------
# /accounts * accounts
# +/ DELETE "accounts_delete_all" Accounts::delete_all
Or you could use accounts_clear
and Accounts::clear
for Name and class method name.
I've ran into some cases that require this action and thought I'd ask here first before cloning your code.
Oo, thanks! I had no idea anyone was actually using the plugin. I was just wrote it to do what I thought would be useful.
Hmm, your request has come at a good time. I've recently implemented the method_map
which maps methods against an element. I've only just released it, so thinking about renaming it to element_method_map
and adding a new collection_method_map
which should do what you want.
I'll see if I can hack something up for you.
OK, I've added this option for you (I think delete_collection
is a more meaningful name, so gone with that for the examples below).
If you want the delete
action to work for every collection
, you can set the collection_method_map
option when loading the plugin.
$self->plugin(
'Restify',
{
collection_method_map =>
{delete => 'delete_collection', get => 'list', post => 'create'}
}
);
or when creating a specific collection
$r->collection(
'accounts',
{
collection_method_map =>
{delete => 'delete_collection', get => 'list', post => 'create'},
}
);
or if you use the restify routes helper
$self->restify->routes(
$r,
{
accounts => [
undef,
{
collection_method_map => {
delete => 'delete_collection',
get => 'list',
post => 'create',
}
}
]
}
);
Thanks! Great solution, working well.