简体   繁体   English

AngularJs $资源动态URL

[英]AngularJs $resource dynamic URL

I have this REST service, which speaks with LDAP server. 我有这个REST服务,它与LDAP服务器说话。 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. 因为LDAP中的用户是由属性描述的,所以我想只获得一些并非所有属性。 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? 如何在使用AngularJS $资源时为属性列表创建此动态URL?

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

    return User;
}])

The first URL you describe follows RESTful convention, but not the second one. 您描述的第一个URL遵循RESTful约定,但不是第二个。 When there are actions verbs (here displayName) in URIs, your API is no longer RESTful. 当URI中有动作动词(此处为displayName)时,您的API不再是RESTful。

AngularJS $resource interacts with RESTful server-side data sources only. AngularJS $资源仅与RESTful服务器端数据源交互。 Your API must follow a lot of RESTful conventions. 您的API必须遵循许多RESTful约定。

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 . 由于您的API不符合这些条件,因此您必须基于较低级别的$ http服务构建自己的类资源CRUD 服务 ( example here ) 这里的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM