简体   繁体   中英

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.

On B I have this custom remote method:

/api/B/myModel/myMethod/{id}

This method works fine if I access the API explorer on B service.

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:

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 :

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:

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? Did I missed something on the configuration?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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