How to define a path section in custom actions of $resource?

Is it possible to specify the path of a custom $resource action ?

I would like to write something like:

angular.module('MyServices', [ 'ngResource' ]).factory('User', [ '$resource', ($resource)->
  $resource('/users', {}, {
    names: { path: '/names', method: 'GET', isArray: true }
  })
])

So I can use it like:

User.names() # GET /users/names

It is not directly supported in the current version of AngularJS but there is a pull request open so there is chance that it will be supported in the near future.

Till then you've got 3 options:

1) Play with variables in the path:

$resource('/users/:names', {}, {
    names: { params: {names: 'names'}, method: 'GET', isArray: true }
  })

2) Use the $http service instead

3) Try the code from the mentioned PR on the monkey-patched version of AngularJS

Check the logs in this working Plunker (excerpt):

var app = angular.module('plunker', ['ngResource'])
  .controller('MyController', 
    function($scope, $resource) {
      var User = $resource(
        '/users/:action',
        {},
        {
          names:{
            method:'GET', 
            params:{action:'names'}
          }
        }
      );

      $scope.users = User.get();
      $scope.names = User.names();
    }  
  );

A less eloquent, but equally effective method:

var resourceUrl =  '/users';
return $resource(resourceUrl, {}, {
    names: { path: resourceUrl + '/names', method: 'GET', isArray: true }
})

From Angular documentation: https://docs.angularjs.org/api/ngResource/service/$resource you can specify 'url' for your custom action which will override the previous one.

angular.module('MyServices', ['ngResource']).factory('User', ['$resource', ($resource)-> $resource('/users', {}, {
names: { url: '/users/names', method: 'GET', isArray: true }
})])

It works in my project using angular 1.3.10!