Search code examples
pathloopbackjsloopback

loopback remote method path definition issue


I want to define a remote method with the following path:

http://localhost:3000/api/dataSourceTestings/{id}/a

In the dataSourceTesting.json file I defined its path as :
"http": [
        {
          "path": "/{id}/a",
          "verb": "put"
        },
]

But when I send request on this end point it gives me the error that can't found the method for this endpoint. 

Do I need to define a relationship for it or is there any other way to define a remote method for this path?


Solution

  • you should define your remotemethod in dataSourceTesting.js file:

    DataSourceTesting.remoteMethod('putDataSourceTestings', {
        accepts: [
            {arg: 'id', type: 'string'}],
        http: {path:'/:id/a', verb:'put'},
        returns: {arg: 'result', type: 'json'}
    });
    

    then implement your putDataSourceTestings function:

    DataSourceTesting.putDataSourceTestings = function(id, cb){
        //your logic goes here
    }