Composables

useSanctumFetch

How to use useSanctumFetch to fetch data from Laravel API

Usage

Besides useSanctumClient you can directly send a request by using a module-specific version of fetch composable - useSanctumFetch.

This composable uses Nuxt's native createUseFetch factory internally, providing full parity with Nuxt's built-in useFetch.

For complete usage details, options, and return types, see the official Nuxt documentation.

const { data, status, error, refresh, clear } = await useSanctumFetch("/api/users")

// with options
const { data } = await useSanctumFetch("/api/users", {
  method: "GET",
  query: { is_active: true },
})

You can also use type casting to work with the response as an interface:

interface MyResponse {
  name: string
}

const { data } = await useSanctumFetch<MyResponse>("/api/endpoint")
const name = data.value?.name