N
Nuxt2y ago
Mr XQ

Best practice to store API end points

In nuxt2 I used Axios and store my end points under
services/api.js
services/api.js
example : api.js:
export default ($apiClient) => ({
fetchBlog() {
return $apiClient.$get("/blog");
},

latestPosts(test) {
return $apiClient.$get("test");
},
export default ($apiClient) => ({
fetchBlog() {
return $apiClient.$get("/blog");
},

latestPosts(test) {
return $apiClient.$get("test");
},
and I use it inside pages like this: index.js:
const blog= await this.$api.fetchBlog()
const blog= await this.$api.fetchBlog()
What's the best way to store and use API endpoints in nuxt3? thank you.
2 Replies
harlan
harlan2y ago
composables wrap the useFetch function or useAsyncData if you need more control
Mr XQ
Mr XQOP2y ago
Thank you!
Want results from more Discord servers?
Add your server