N
Nuxt8mo ago
PoTTii

Nuxt 3 Repository Pattern - Best Practice?

What is the way to go nowadays to manage API Calls in a repository pattern? I followed a Medium Post (https://medium.com/@luizzappa/nuxt-3-repository-pattern-organising-and-managing-your-calls-to-apis-with-typescript-acd563a4e046), but since Nuxt 3.10 you run into warnings because every method uses useAsyncData and sometimes I'm gonna call a method to be used after a user intreaction, so on client side only. Can anony recommand another way / resource to do it?
Medium
2 Replies
IsraelOrtuno
IsraelOrtuno8mo ago
You can use the repository pattern to wrap your api calls and maybe even do some mappings here and there within classes or functions but I would not use useAsyncData within it By doing that you are also preventing yourself of using these repositories in the server side of your app, where you will also want to use them eventually
IsraelOrtuno
IsraelOrtuno8mo ago
@manniL / TheAlexLichter has a great video about this https://www.youtube.com/watch?v=jXH8Tr-exhI
Alexander Lichter
YouTube
Custom $fetch and Repository Pattern in Nuxt 3
💻 The repository pattern is a popular way to abstract your API calls away and provide a descriptive way to retrieve or send data. But how would you implement it in Nuxt? And should you use composables or $fetch for it? This video will give answers to all the questions! Key points: 🎛️ Implementing the repository pattern in Nuxt 🔛 Creating our ow...
Want results from more Discord servers?
Add your server