How to implement custom / complex operation routes in FeathersJS

余生颓废 提交于 2019-12-01 18:22:58

You can still implement the route using your own service and use the :id as route parameter:

app.use('/Category/disableExclusiveContentsOf/:id', {
  find() {
    // do complex stuff here
  }
});

One thing I'd recommend changing is that the URL seems to be action and not resource oriented. This means that someone can change your application data with a GET request which is generally considered not a good practise (e.g. in some cases the Google crawler came in and deleted/changed a bunch of things).

Feathers encourages you to think in resources rather than custom routes and actions. In your case you would have an ExclusiveContents service that you can POST to:

app.use('/Category/ExclusiveContents/:categoryId', {
  create(data, params) {
    // do complex stuff here
    params.categoryId // the id of the category
    data // -> additional data from the POST request
  }
});
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!