If you look on the docs: https://docs.angularjs.org/api/ngResource/service/$resource
Scroll down to where you can see Returns.
You will see this list:
{ 'get': {method:'GET'},
'save': {method:'POST'},
'query': {method:'GET', isArray:true},
'remove': {method:'DELETE'},
'delete': {method:'DELETE'} };
This is where it tells you what is defined on the $resource
object by default. As you can see if you call get
then you will use HTTP GET
, save
=> HTTP POST
.
So if you define this:
var User = $resource('/user/:userId', {userId:'@id'});
Then you can perform a GET
:
var user = User.get({userId:123}, function() {
user.abc = true;
user.$save();
});
If you define this:
var User = $resource('/user/:userId', {userId:'@id'}, {specialAction: {method: 'POST'}});
And call it:
User.specialAction({someParam:someValue});
You will perform the same action as save
. You have just renamed it :)
So $resource
just wraps around $http
to make using RESTful API's easier. You can defined your own set of methods if you wish, you can specify to great detail how these are supposed to be executed.