supastarter for NuxtAPI
Use API in frontend
You can use the endpoints with the help of the auto-imported composable useApiCaller()
. This composable exposes a tRPC Nuxt Client.
Using a data loading composable
If you want to have features like caching, pending, errors, etc., you can use the .useQuery()
or .useLazyQuery()
methods, which are built on top of Nuxt useAsyncData
.
This only works inside <script setup>
. If you want to call your endpoints inside utils, composables, or anywhere else,
use .query()
.
If you want to load the data lazily (meaning that you will have to handle the loading state), you can do that like so:
Using the API caller directly
If you want to call your endpoints inside utils, composables, or anywhere else, use .query()
: