Alexander Lichter Custom $fetch and Repository Pattern in Nuxt 3
π― ΠΠ°Π³ΡΡΠΆΠ΅Π½ΠΎ Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΈ ΡΠ΅ΡΠ΅Π· Π±ΠΎΡΠ°:
π« ΠΡΠΈΠ³ΠΈΠ½Π°Π» Π²ΠΈΠ΄Π΅ΠΎ:
πΊ ΠΠ°Π½Π½ΠΎΠ΅ Π²ΠΈΠ΄Π΅ΠΎ ΠΏΡΠΈΠ½Π°Π΄Π»Π΅ΠΆΠΈΡ ΠΊΠ°Π½Π°Π»Ρ Β«Alexander LichterΒ» (@TheAlexLichter). ΠΠ½ΠΎ ΠΏΡΠ΅Π΄ΡΡΠ°Π²Π»Π΅Π½ΠΎ Π² Π½Π°ΡΠ΅ΠΌ ΡΠΎΠΎΠ±ΡΠ΅ΡΡΠ²Π΅ ΠΈΡΠΊΠ»ΡΡΠΈΡΠ΅Π»ΡΠ½ΠΎ Π² ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΠΎΠ½Π½ΡΡ
, Π½Π°ΡΡΠ½ΡΡ
, ΠΎΠ±ΡΠ°Π·ΠΎΠ²Π°ΡΠ΅Π»ΡΠ½ΡΡ
ΠΈΠ»ΠΈ ΠΊΡΠ»ΡΡΡΡΠ½ΡΡ
ΡΠ΅Π»ΡΡ
. ΠΠ°ΡΠ΅ ΡΠΎΠΎΠ±ΡΠ΅ΡΡΠ²ΠΎ Π½Π΅ ΡΡΠ²Π΅ΡΠΆΠ΄Π°Π΅Ρ Π½ΠΈΠΊΠ°ΠΊΠΈΡ
ΠΏΡΠ°Π² Π½Π° Π΄Π°Π½Π½ΠΎΠ΅ Π²ΠΈΠ΄Π΅ΠΎ. ΠΠΎΠΆΠ°Π»ΡΠΉΡΡΠ°, ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΡΠ΅ Π°Π²ΡΠΎΡΠ°, ΠΏΠΎΡΠ΅ΡΠΈΠ² Π΅Π³ΠΎ ΠΎΡΠΈΠ³ΠΈΠ½Π°Π»ΡΠ½ΡΠΉ ΠΊΠ°Π½Π°Π».
βοΈ ΠΡΠ»ΠΈ Ρ Π²Π°Ρ Π΅ΡΡΡ ΠΏΡΠ΅ΡΠ΅Π½Π·ΠΈΠΈ ΠΊ Π°Π²ΡΠΎΡΡΠΊΠΈΠΌ ΠΏΡΠ°Π²Π°ΠΌ Π½Π° Π΄Π°Π½Π½ΠΎΠ΅ Π²ΠΈΠ΄Π΅ΠΎ, ΠΏΠΎΠΆΠ°Π»ΡΠΉΡΡΠ°, ΡΠ²ΡΠΆΠΈΡΠ΅ΡΡ Ρ Π½Π°ΠΌΠΈ ΠΏΠΎ ΠΏΠΎΡΡΠ΅ support@, ΠΈ ΠΌΡ Π½Π΅ΠΌΠ΅Π΄Π»Π΅Π½Π½ΠΎ ΡΠ΄Π°Π»ΠΈΠΌ Π΅Π³ΠΎ.
π ΠΡΠΈΠ³ΠΈΠ½Π°Π»ΡΠ½ΠΎΠ΅ ΠΎΠΏΠΈΡΠ°Π½ΠΈΠ΅:
π» 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 own $fetch instance
βΌοΈ Making sure that it works with composables and standalone
π©βπ» Building the demo app step by step
---
Links:
πΊοΈ Do you use useFetch wrong?! -
π Sebastien Chopinβs blog post about custom $fetch -
πΊοΈ Class Serialization Errors -
π Code -
π My repository pattern blog post
Donβt forget to hit that βSubscribeβ button, ring the notification bell and give a thumbs up!
π Connect further:
Website:
Twitter/X:
Twitch:
Chapters:
Intro
A warning when misusing useAsyncData or useFetch
Demo app
Implementing the repository pattern
Passing a $fetch instance
Creating our own $fetch instance
Globally providing $fetch using runtimeConfig
Summary
Keywords:
repository pattern nuxt nuxt3 custom $fetch fetch