angular-restmod icon indicating copy to clipboard operation
angular-restmod copied to clipboard

Provide easy way to override HTTP method for restmod methods

Open smashercosmo opened this issue 10 years ago • 1 comments

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)

smashercosmo avatar Oct 14 '14 10:10 smashercosmo

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.

iobaixas avatar Oct 14 '14 18:10 iobaixas