Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom endpoints for CRUD actions #270

Open
tomvanvegchel opened this issue Feb 21, 2023 · 1 comment
Open

Custom endpoints for CRUD actions #270

tomvanvegchel opened this issue Feb 21, 2023 · 1 comment

Comments

@tomvanvegchel
Copy link

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?

@gajosadrian
Copy link

gajosadrian commented Oct 14, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants