Unified request function
- Dominant language
- JavaScript
- Stars
- 226
- Forks
- 235
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 19
Description
At the moment, we send requests in one of three different ways:
1. Using the `request()` method of a `requestData` resource
2. Using a method from the `request` mixin
3. Using `http` in the container directly (`http` is set to axios)
(1) and (2) are both common. (3) is uncommon and maybe only happens for the logout request.
(1) and (2) do a lot of the same things, for example, around error handling, so they have some near-duplicate code. That's mostly a historical artifact, reflecting that things like showing an alert worked differently within the Vuex store vs. within components. We no longer have a Vuex store, and everything can now use the container to access app-wide state, so I think we're now well positioned to move that shared logic into a function that both `requestData` and the mixin can call. Once we have a function like that, cases like (3) could also call it.
I still think it makes sense to have multiple ways of sending requests. `requestData` resources have one way of storing request state, but components need a separate mechanism. And requests sent by resources vs. requests sent by components have slightly different lifecycles: they can be canceled in different ways. So the goal of this issue isn't to remove all distinctions between these different ways of sending requests, but rather to reduce duplicate code and to remove distinctions that aren't necessary. For example, we used to document that the `request` module of the Vuex store was strictly for GET requests, while the `request` mixin was for non-GET requests. However, `requestData` resources are now able to send non-GET requests, and I think the `request` mixin should be allowed to send GET requests as well. (Not that we should necessarily encourage that pattern given that components can now create local resources, which will usually be the most convenient approach.)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.