3

I have this REST service, which speaks with LDAP server. In order to get all available data about user, I must visit this:

GET /users/:userId

Because user in LDAP is described by attributes, I want to get only some not all attributes. In this case must do this:

GET /users/:userId/o/mail/displayName/....(list of attributes required)

How to create this dynamic url for attribute list while using AngularJS $resource?

.factory('User', ['$resource', 'REST_API_URL', function ($resource, REST_API_URL) {
    var User = $resource(
                REST_API_URL + '/users/:id', 
                {id: '@id'}
        );

    return User;
}])
scniro
  • 16,844
  • 8
  • 62
  • 106
andrius.k
  • 799
  • 1
  • 10
  • 26

1 Answers1

2

The first URL you describe follows RESTful convention, but not the second one. When there are actions verbs (here displayName) in URIs, your API is no longer RESTful.

AngularJS $resource interacts with RESTful server-side data sources only. Your API must follow a lot of RESTful conventions.

I recommend you read answers to this question which is highly related and describe those conventions.

As your API does not meet these criteria you will have to build your own $resource-like CRUD service based on the lower-level $http service. (example here)

Community
  • 1
  • 1
Pak
  • 2,123
  • 22
  • 28
  • 1
    You can anyway override resource methods to specify custom Url: var Order = $resource('myUrl/:orderId', {orderId : "@orderId"}, { query:{ method : 'GET', isArray : false, url: 'myCustomUrl', } } ); – teone Jun 12 '15 at 15:17