Skip to content
On this page


Returns KQL query data. Uses an internal server route to proxy requests.

Query responses are cached by default between function calls for the same query based on a calculated hash.

Type Declarations

function useKql<
  ResT extends KirbyQueryResponse = KirbyQueryResponse,
  ReqT extends KirbyQueryRequest = KirbyQueryRequest,
  query: MaybeRefOrGetter<ReqT>,
  opts?: UseKqlOptions<ResT>,
): AsyncData<ResT, FetchError>

type UseKqlOptions<T> = AsyncDataOptions<T> & Pick<
  | 'onRequest'
  | 'onRequestError'
  | 'onResponse'
  | 'onResponseError'
  | 'headers'
> & {
   * Language code to fetch data for in multi-language Kirby setups
  language?: string
   * Skip the Nuxt server proxy and fetch directly from the API.
   * Requires `client` to be enabled in the module options as well.
   * @default false
  client?: boolean
   * Cache the response between function calls for the same query
   * @default true
  cache?: boolean

useKql infers all of Nuxt's useAsyncData options.

Return Values

  • data: the result of the KQL query
  • pending: a boolean indicating whether the data is still being fetched
  • refresh: a function that can be used to refresh the data returned by the handler function
  • error: an error object if the data fetching failed

By default, Nuxt waits until a refresh is finished before it can be executed again. Passing true as parameter skips that wait.


<script setup lang="ts">
const { data, pending, error, refresh } = await useKql({
  query: 'site',
  select: ['title', 'children']

    <h1>{{ data?.result?.title }}</h1>
    <button @click="refresh()">

Allow Client Requests


Authorization credentials will be publicly visible. Also, possible CORS issues ahead if the backend is not configured properly.

To fetch data directly from your Kirby instance, without the Nuxt proxy, set the option client to true:

const { data } = await useKql(
  { client: true }

This requires the client option to be true in your nuxt-kql module configuration:

// `nuxt.config.ts`
export default defineNuxtConfig({
  modules: ['nuxt-kql'],

  kql: {
    client: true

Released under the MIT License.