Expose merged config in request
See original GitHub issueThe change from version 0.5 removed the ability to inject url parameters into the request for the model.
It is still possible to recover some of this by setting in the model:
static apiConfig = {
url: '/foo/',
};
and only use api().request({}).
I would like to recover all of the functionality by exposing the built config in the Request object returned by api(). This will let me modify the url
property to inject parameters before calling request({}).
The alternative is to restore the original functionality by accepting an object in place of the url for the Request functions that will check if url
has been set in the config and replace its keys in the url path with its values.
Update: I just noticed I can monkeypatch the Request object with my own functions and that the config isn’t available until the method call: https://github.com/vuex-orm/plugin-axios/blob/5c6f51135a58c4caa8b40234f8dd303c75626da2/src/api/Request.ts#L117-L123
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top GitHub Comments
@JKrol sure, you can define common options at model level as documented.
However, simply invoking
User.api().get()
without a URL is not possible. It’s not how axios functions.If you want pre-configured or shorthand methods to simply invoke anywhere in your application, consider using Custom Actions which are designed to accommodate your exact requirements.
I have similar question. Currently, each time I want to call API, I have to provide the URL. It would be great to have an option, to define the URL on the model level.
Example - lets say I have a User model. Now I want to call
get
on the user - I have to write:If I have many places in code where I want to get users, I have to provide ‘/api/users’ URL in each place. It would be great to have a possibility to define URL in User model and then just call:
Is this possible?