[英]Using loopback-connector-remote to call custom method in another loopback service doesn't create correct URL
I'm trying to connect 2 loopback services, let's say A and B , using loopback-connector-remote datasource.我正在尝试使用loopback-connector-remote数据源连接 2 个环回服务,比如说A和B 。
On B I have this custom remote method:在B我有这个自定义远程方法:
/api/B/myModel/myMethod/{id}
This method works fine if I access the API explorer on B service.如果我访问B服务上的 API 资源管理器,则此方法工作正常。
Then on A service I want to access this method so I created the following configuration (which is the same on B too) on the remote model object:然后在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 I can do any call to B like find, findById, etc. But When I call this custom method I get this error on A :从A我可以对B进行任何调用,例如 find、findById 等。但是当我调用此自定义方法时,我在A上收到此错误:
strong-remoting:rest-adapter Error in GET /myModel/myMethod/1231: Error: id must be a number
strong-remoting:rest-adapter Error in GET /myModel/myMethod/1231: Error: id must be a number
And looking at the logs in B I saw that A is calling the service like this:查看B中的日志,我看到A正在像这样调用服务:
strong-remoting:rest-adapter Error in GET /myModel/myMethod/:id?id=1231: Error: id must be a number
strong-remoting:rest-adapter Error in GET /myModel/myMethod/:id?id=1231: Error: id must be a number
Why is strong-remoting or loopback-connector-remote not replacing the id correctly when the URL is created?为什么在创建 URL 时, strong-remoting或loopback-connector-remote没有正确替换 id? Did I missed something on the configuration?
我在配置上遗漏了什么吗?
需要在A服务模型对象的远程方法配置中添加源路径:
{ arg: 'id', type: 'number', required: true, http: { source: 'path' }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.