Skip to content

Custom endpoints for CRUD actions #270

@tomvanvegchel

Description

@tomvanvegchel

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions