Angularjs $resource vs $http

Handsontable JavaScript Spreadsheet Most popular component for web apps

Angularjs $resource vs $http… Which one do you use?

Some Answers I found:

  • $http is for general purpose AJAX for use with GET, POST, DELETE etc…
  • $resource wraps $http for use in RESTful web API scenarios…

So with a $resource, you can call a GET to get the resource as a JavaScript object, then alter it and send it back with a POST, or even delete it with DELETE.

  • $resource is just a higher abstraction on the top of $http, so if $resource fits your needs, use it.
  • Even if you are using $resource, you can use $httpBackend mock for testing it.
  • $resource talks to $http, $http talks to $httpBackend (which you mock out during unit test).
  • Check out$httpBackend

The best Answer I found:

I think putting $http requests into a service just generally works out better because you want to have access to the data from multiple locations and the service acts as a singleton so basically you can handle any kind of caching you want to do there and controllers can all just watch the appropriate services to update their own data. I’ve found that a combo of $watch in the controllers for data on the service and returning the promises from my service’s methods gives me the most flexibility with how to update things in the controller.


Sam Deering

Sam Deering

Sam is a web developer, online entrepreneur and investor. In his spare time he enjoys coding, playing chess and sharing what he learns with others.

Leave a Reply

Your email address will not be published. Required fields are marked *