Replace api-service
concept with Nuxt context-stored Axios instance
#530
Labels
💻 aspect: code
Concerns the software code in the repository
🧰 goal: internal improvement
Improvement that benefits maintainers, not users
🟩 priority: low
Low priority and doesn't need to be rushed
🧱 stack: frontend
Related to the Nuxt frontend
Problem
See https://github.com/WordPress/openverse-frontend/pull/1569/files#r933336938 for a description of the problem and a suggested solution. The discussion is copied here for posterity:
Prompted by @krysal's question which uncovered the assumption.
Basically it boils down to the fact that I think the
api-service
concept no longer serves us and in fact overcomplicates and bakes in incorrect assumptions about how API versioning works or can be used.I am skeptical that we need an API service at all. If there are abstractions that can exist to simplify certain request areas, they can be baked into the areas that make those requests instead of into the loose service class model that doesn't suite a JavaScript request/response lifecycle very well (considering we don't have a DI container or anything else like that to make easy instantiation, dependency management, and further abstractions clean).
Description
Remove the
api-service
abstraction and replace it with the typical Nuxt plugin axios instance that has been appropriately instantiated with an API token when needed. Use request interceptors to do other transformations that might be helpful for downstream usages of the axios instance (like trailing slash enforcement).Alternatives
Keep the current api service concept but untangle versioning from it entirely.
I don't think this is a good approach because it preserves the complexity of every single requester having to know about and manage the API token.
Implementation
The text was updated successfully, but these errors were encountered: