我们如何覆盖默认的loopback REST API模型 endpoints ?例如,我想在调用以下GET API时调用名为 list 的自定义模型方法 .
我指的是文档https://loopback.io/doc/en/lb2/Exposing-models-over-REST.html
1.环回资源管理器的API endpoints :http://localhost:3000/api/Assets
2.Model方法定义:
Asset.list = function(cb) {
console.log("called");
}
Asset.remoteMethod('list', {
http: {path: '/'},
returns: {type: 'Object', root: true}
});
1 回答
您的
console.log("called");
应仅出现在您的终端中,而不是在您的网络浏览器上显示 - 此时_2960703不会看到它 .如果要在Web浏览器上看到某些内容,则必须为回调返回一个值,例如:
此文件应位于common / model / asset.js中
在您的server / model-config.json中,不要忘记引用您的模型: