0
votes

I've recently tried to make a somewhat simple implementation of a POST HTTP handler with LoopBack but didn't manage to. This is the case. When I create a model class it seems that I can only add remote method to implement business functionality. But what if I want to handle the request myself in a proper way in response of a POST request ? It's not very RESTFul to add special methods with names rather than implementing proper handling of a HTTP verb request. Is there any way to achieve that ? Thanks.

1
You might want to consider remote hooks or operation hooks in case you want to add some extra logic for your model on top of standard CRUD functionality exposed by automatically generated REST API. - Ivan Schwarz
Thanks Ivan. What I needed exactly was to replace the predefined behavior and Richard's answer totally fited the purpose. - redlab

1 Answers

1
votes

You can define your own verb and path for the method as follows:

MyModel.myMethod = function(...) { ... }

MyModel.remoteMethod('myMethod', {
  accepts: ...,
  returns: ...,
  http: {
    verb: 'post',
    path: '/'
  }
});

When would attach the myMethod function to the /api/MyModels/ endpoint.

For further docs on remote methods checkout the following:

For the 2nd link, a sharedMethod is what gets created when you use the MyModel.remoteMethod(...) function.