N
Nuxt11mo ago
cmcnicholas

Invoke `/api` endpoint from another `/api` endpoint

I have some shared data that can be requested from /api/items using defineCachedEventHandler which works great. I have another call /api/items/<some-id> again using defineCachedEventHandler where I could fetch individually from my backend but the number of items is stable at ~200-300. I get the list of these in 1-2 api calls and after doing so my cache is warm. What I want to do is: /api/items/xxx -> calls /api/items to fetch the item as I am confident that 99.99% of the calls will already have a populated cache and if not this action would populate said cache. Is there a way to have nuxt server methods invoke each other but not over http request as this is just expensive and wasteful? Otherwise I will most likely create a singleton in the service to store these items and both endpoints in /api will just invoke that but was hoping Nuxt and its defineCachedEventHandler could take care of this for me and I can just invoke one from another.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server