0

I'm exploring how jhipster manipulates data. I have found $http.get() in getProfileInfo method in ProfileService Service whitch interacting restful api :

function getProfileInfo() {
            if (!angular.isDefined(dataPromise)) {
                dataPromise = $http.get('api/profile-info').then(function(result) {
                    if (result.data.activeProfiles) {
                        var response = {};
                        response.activeProfiles = result.data.activeProfiles;
                        response.ribbonEnv = result.data.ribbonEnv;
                        response.inProduction = result.data.activeProfiles.indexOf("prod") !== -1;
                        response.swaggerDisabled = result.data.activeProfiles.indexOf("no-swagger") !== -1;
                        return response;
                    }
                });
            }
            return dataPromise;
        }

and some where i have found $resouce() manipulating GET method. for example in BankAccount factory :

var resourceUrl =  'api/bank-accounts/:id';

I searched for when to use $http and when to use $resource and i found this :

AngularJS $http and $resource

why hipster is not following consistent way of interacting API and manipulating data!!?

so jhipster, when to use $http and when to use $resource in services??

Community
  • 1
  • 1
Hadi Rasouli
  • 1,871
  • 3
  • 27
  • 43

2 Answers2

2

We use $resource when requesting a RESTful endpoint, for example for an entity. $resource provides basic REST operations easily whereas $http is more specific.

For profile we only need to GET /profile-infos so it's useless to use $resource because we'll never need to call POST or DELETE on that URL.

1

$http will fetch you the entire page or complete set of data from a given URL whereas $resouce uses http but will help you to fetch a specific object or set of data. $resource is fast and we use it when we need to increase the speed of our transaction. $http is used when we are concerned with the time.

Vikash Kumar
  • 1,712
  • 1
  • 11
  • 17
  • Have you made some measurements? I don't think few mili seconds in browser matter. – Gaël Marziou Jul 07 '16 at 11:22
  • Yes it does matter when thousands of people are accessing a common page and they need it quick. $resource improves performance and is capable of providing loose coupling. – Vikash Kumar Jul 07 '16 at 11:45