How to implement custom / complex operation routes in FeathersJS

前端 未结 1 1395
广开言路
广开言路 2021-01-19 07:25

I need to implement a bunch of routes that do very custom / complex operations on a FeathersJS app.

One of those routes is /Category/disableExclusiveContentsOf

相关标签:
1条回答
  • 2021-01-19 07:53

    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
      }
    });
    
    0 讨论(0)
提交回复
热议问题