robsontenorio/vue-api-query

Custom endpoints for CRUD actions

Opened this issue · 1 comments

Is there a way to implement custom endpoints for CRUD actions using the current setup of vue-api-query?
There is a .custom() method to create a custom endpoint for a model which works great however is only usable for GET requests to my understanding.

I would like to be able to make custom endpoints for certain actions on a model e.g.: /model-resource/model-action.
Currently, I do this by creating a new model stored away in an actions namespace with as resource the action endpoint e.g.:

export default class ActionModel extends Model {
    resource() {
        return 'model-action';
    }
}

I then build up the query as: new ActionModel({}).for(Model);
This results in an endpoint that I can use for my custom model actions, however, this approach is quite ugly as you are creating a model only to use its resource() method.
This is essentially misusing the relations setup from the .for() method by creating a new ActionModel which doesn't have an ID.

Could it be possible to use the .custom() method for CRUD actions, or is there a way that we could create specific endpoints on the model for certain actions?

I believe that using Active Record, like the one offered by this package, might not be the best approach for handling save and get requests. I am contemplating a separation of these responsibilities into two distinct components: Command, represented by ModelService (which can potentially make use of this package), and Query, embodied by Model (utilizing this package). This approach aligns with the principles of Command–Query Separation (CQRS).

In summary, the .custom() method excels in its own design, but when dealing with requests that modify Models, I would advocate for separating these into dedicated model Services.