如何通过Sails中的rest调用获取模型的属性

时间:2016-05-10 15:34:43

标签: node.js rest sails.js

我希望通过HTTP REST调用获取模型的属性。我想知道属性名称和数据类型。我怎样才能做到这一点?

一个例子是我想获得user模型的属性。所以我想进行一次HTTP调用,例如GETlocalhost/users/attributes,它会返回:

{
    id: integer,
    username: string,
    ...
}

我怎样才能做到这一点?感谢。

1 个答案:

答案 0 :(得分:0)

实际上,我找到了答案。我在模型的controller.js文件上做了一个路线。我补充说:

    module.exports = {

            attributes: function (req, res) {
            var message = sails.models.categories.attributes;
            console.log(message);
            res.json(message);

        }
    };

然后我导航到localhost/<model name>/attributes