Under this particular service:
vdgServices.factory('UserService', ['$resource',
function($resource) {
return $resource('api/users/:id', {}, {
doGet: {
method: 'GET',
params: { id: '@userId' }
},
doPost: {
method: 'POST',
params: { id: '@userId' }
},
doPut: {
method: 'PUT',
params: { id: '@userId' }
},
doDelete: {
method: 'DELETE',
params: { id: '@userId' }
}
});
}]);
I have noticed the different URLs being requested as follows:
var params = { userId: 42 };
var onSuccess = function() { console.log("OK"); };
var onError = function() { console.log("KO"); };
UserService.doGet(params, onSuccess, onError);
// requests api/users?userId=42
UserService.doPost(params, onSuccess, onError);
// requests api/users/42
UserService.doPut(params, onSuccess, onError);
// requests api/users/42
UserService.doDelete(params, onSuccess, onError);
// requests api/users?userId=42
Could someone clarify why the :id
URL parameter is sometimes substituted with 42
, and other times not?
Ideally, I would prefer it to be replaced consistently for all methods, resulting in the URL "api/users/42" every time.