使用 loopback-connector-remote 在另一个环回服务中调用自定义方法不会创建正确的 URL
Using loopback-connector-remote to call custom method in another loopback service doesn't create correct URL
我正在尝试连接 2 个环回服务,比方说 A 和 B,使用 loopback-connector -远程 数据源。
在 B 我有这个自定义远程方法:
/api/B/myModel/myMethod/{id}
如果我在 B 服务上访问 API 资源管理器,此方法工作正常。
然后在 A 服务上我想访问这个方法所以我创建了以下配置(在 B 上也一样)在远程模型对象上:
myModel.remoteMethod(
'myMethod',
{
http: {path: '/myMethod/:id', verb: 'get'},
accepts: [
{arg: 'id', type: 'number', required: true}
],
returns: {type: 'object', root: true}
}
);
From A 我可以对 B 进行任何调用,例如查找、findById 等。但是当我调用此自定义方法时,我得到A 上的这个错误:
strong-remoting:rest-adapter Error in GET /myModel/myMethod/1231: Error: id must be a number
查看 B 中的日志,我看到 A 正在这样调用服务:
strong-remoting:rest-adapter Error in GET /myModel/myMethod/:id?id=1231: Error: id must be a number
为什么 strong-remoting 或 loopback-connector-remote 在创建 URL 时没有正确替换 id ?我是否遗漏了一些配置信息?
需要将源路径添加到 A 服务模型对象中的远程方法配置:
{ arg: 'id', type: 'number', required: true, http: { source: 'path' }}
我正在尝试连接 2 个环回服务,比方说 A 和 B,使用 loopback-connector -远程 数据源。
在 B 我有这个自定义远程方法:
/api/B/myModel/myMethod/{id}
如果我在 B 服务上访问 API 资源管理器,此方法工作正常。
然后在 A 服务上我想访问这个方法所以我创建了以下配置(在 B 上也一样)在远程模型对象上:
myModel.remoteMethod(
'myMethod',
{
http: {path: '/myMethod/:id', verb: 'get'},
accepts: [
{arg: 'id', type: 'number', required: true}
],
returns: {type: 'object', root: true}
}
);
From A 我可以对 B 进行任何调用,例如查找、findById 等。但是当我调用此自定义方法时,我得到A 上的这个错误:
strong-remoting:rest-adapter Error in GET /myModel/myMethod/1231: Error: id must be a number
查看 B 中的日志,我看到 A 正在这样调用服务:
strong-remoting:rest-adapter Error in GET /myModel/myMethod/:id?id=1231: Error: id must be a number
为什么 strong-remoting 或 loopback-connector-remote 在创建 URL 时没有正确替换 id ?我是否遗漏了一些配置信息?
需要将源路径添加到 A 服务模型对象中的远程方法配置:
{ arg: 'id', type: 'number', required: true, http: { source: 'path' }}