angular-restmod
angular-restmod copied to clipboard
Provide easy way to override HTTP method for restmod methods
It's very messy to override the whole function when we, for example, just need to use POST instead of GET for $fetch method. It would be great if we could just use something like
restmod.model().mix({
$extend: {
Resource: {
$fetch: { method: 'POST' }
}
}
})
(Or may be there is a way to do it, but simply it's not in the docs or I just couldn't find it)
You could override the function and decorate it to change it's behaviour without rewriting the whole thing.
restmod.model().mix({
$extend: {
Resource: {
$fetch: function(_params) {
return this.$decorate({
'before-request': function(request_config) {
request_config.method = 'POST';
request_config.data = _params;
}
}, function() {
return this.$super();
});
}
}
})
$decorate
usage can be found in the hooks guide. I agree is sort of messy though, I've been thinking about custom actions support, but I'm yet to find a good approach.