loopbackio / loopback-connector-rest

Connect Loopback to a REST API
http://loopback.io/doc/en/lb2/REST-connector.html
Other
75 stars 81 forks source link

How to change method route #139

Closed cgoguyer closed 5 years ago

cgoguyer commented 5 years ago

Hello, I have defined custom methods (via template) for find and findById and I'd like to change the default generated route by CRUD like routes.

With template I get the following routes: GET http://apiRoot/myModel/find and I'd like to have GET http://apiRoot/myModel GET http://apiRoot/myModel/findById/:id and I'd like to have GET http://apiRoot/myModel/:id

So how to change default route methods in rest connector ? Thank you.

dhmlau commented 5 years ago

@raymondfeng @jannyHou, could you please with this question? Thanks.

jannyHou commented 5 years ago

@cgoguyer You probably need to hack the code in loopback/lib/persisted-model.js using setRemoting

cgoguyer commented 5 years ago

@jannyHou, I'm using a model based on "Model" to map custom third party API and I want to expose them as CRUD endpoints. I'm looking for a way to define the path for a method within the rest connector => map function apiCustomFind to / Thx.

raymondfeng commented 5 years ago

@cgoguyer You can always define another model as the facade and use the REST model as the implementation for delegation. For example:

FacadeModel

GET /apiRoot/myModel
  FacadeModel.find = function(...) {

   FacadeModel.app.RestModel.find(...);
}
cgoguyer commented 5 years ago

@raymondfeng, Ok, Facade Models is a good approach to solve this problem. Thx.