$kql
Returns raw KQL query data. Uses an internal server route to proxy requests.
Query responses are cached by default.
Type Declarations
ts
function $kql<T extends KirbyQueryResponse = KirbyQueryResponse>(
query: KirbyQueryRequest,
opts: KqlOptions = {},
): Promise<T>
type KqlOptions = Pick<
FetchOptions,
| 'onRequest'
| 'onRequestError'
| 'onResponse'
| 'onResponseError'
| 'headers'
> & {
/**
* Language code to fetch data for in multilang 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
*/
client?: boolean
}
Example
vue
<script setup lang="ts">
const data = await $kql(
{
query: 'site',
select: ['title', 'children']
},
{
async onRequest({ request }) {
console.log(request)
},
async onResponse({ response }) {
console.log(response)
},
async onRequestError({ error }) {
console.log(error)
},
async onResponseError({ error }) {
console.log(error)
},
}
)
</script>
<template>
<div>
<h1>{{ data?.result?.title }}</h1>
</div>
</template>