angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

feat($resource): pass isArray to http config

Open tautvilas opened this issue 10 years ago • 4 comments

This will allow to indentify request type in global interceptor.

I need to identify if request is array or object and put necessary array or object to httpCache accordingly if request does not need to be made.

tautvilas avatar Oct 16 '15 08:10 tautvilas

I don't get the usecase (and I suspect this might not be something commonly useful to include in core). Could you provide more details on why you need this/how you will use this ? (An example maybe ?)

gkalpak avatar Oct 16 '15 11:10 gkalpak

You are right, this is not a common usecase. But, why drop isArray param? I would expect all data that I enter in resource configuration to be found in http config object. I can find cache, method, header and transformer params, so why no isArray?

tautvilas avatar Oct 16 '15 12:10 tautvilas

Hm...good point. As a work-around, you can pass your custom param (but you must be in charge of all $resources and it's less than ideal). E.g.:

var Thing = $resource('/api/thing/:id', {id: '@id'}, {
  query: {method: 'GET', isArray: true, itsAnArray: true}
});
// ...then look for `config.itsAnArray` in your interceptor

Regarding the question "why not to include isArray": I guess it was skipped in the first place, because it is a $resource-specific property and doesn't have any usefulness for $http. On the other hand, it is (kind of) related to/characterizing the request.

I could definitely leave with passing isArray to $http. So, it LGTM after all.

Let's see what other people have to say.

gkalpak avatar Oct 16 '15 13:10 gkalpak

Thanks, I will implement temporary workaround and will wait for what you decide

tautvilas avatar Oct 16 '15 13:10 tautvilas