繁体   English   中英

使用 loopback-connector-remote 在另一个环回服务中调用自定义方法不会创建正确的 URL

[英]Using loopback-connector-remote to call custom method in another loopback service doesn't create correct URL

我正在尝试使用loopback-connector-remote数据源连接 2 个环回服务,比如说AB

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}
    }
 );

A我可以对B进行任何调用,例如 find、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

为什么在创建 URL 时, strong-remotingloopback-connector-remote没有正确替换 id? 我在配置上遗漏了什么吗?

需要在A服务模型对象的远程方法配置中添加源路径:

{ arg: 'id', type: 'number', required: true, http: { source: 'path' }}

暂无
暂无

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

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