Ravikiran Tadepalli
Ravikiran Tadepalli

Reputation: 21

What is the difference between $http and $resource?

Can I use either for a REST call ? Or is there some minor difference ? I have used both of them in my projects with no side effects,

Upvotes: 0

Views: 4943

Answers (1)

Thangadurai
Thangadurai

Reputation: 544

These are the main differences between $http and $resource:

$http:

  1. $http is for universal purpose. It is an Ajax call.
  2. $http is built into the AngularJS framework.
  3. $http is good for quick retrieval.
  4. $http is injected directly into an AngularJS controller by the developer.

For more details about $http refer: https://docs.angularjs.org/api/ng/service/$http

$resource:

  1. $resource wraps $http to use in RESTful web APIs.
  2. $resource needs to add the module separately.
  3. $resource is good for conditions slightly more complex than $http.
  4. $resource does not allow us to do much with data once it is consumed in the application. It is in the final state when it is delivered to the HTML DOM. The data are the same that the $http method will receive.

For more details about $resource refer: https://docs.angularjs.org/api/ngResource/service/$resource

You can find more answer here and here.

Upvotes: 5

Related Questions