Malave
Malave

Reputation: 43

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?

Upvotes: 1

Views: 500

Answers (1)

Malave
Malave

Reputation: 43

Needed to add source path to the remote method configuration in the A service model object:

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

Upvotes: 1

Related Questions