# Kirby 3 as Headless CMS for Vue/Nuxt

**URL:** <https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142>\
**Category:** Questions\
**Tags:** v3\
**Created:** [January 15, 2019, 3:50pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142 "2019-01-15T15:50:55Z")\
**Posts on this page:** 9\
**Page:** 5

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 28, 2020, 4:51pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/81 "2020-05-28T16:51:55Z")

</div>

> [@sicnarf](#):
>
> Have you published a Cookbook recipe for this? I’m not able to find it.

No, I’m afraid there is no recipe for this. Anyone volunteering?

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [July 30, 2020, 8:33am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/82 "2020-07-30T08:33:19Z")

</div>

> **[getkirby/kql](https://github.com/getkirby/kql)**
>
> Kirby's Query Language API combines the flexibility of Kirby's data structures, the power of GraphQL and the simplicity of REST. - getkirby/kql

---

<div class="post-metadata">

**Author:** ![trych](https://avatars.discourse-cdn.com/v4/letter/t/5e9695/32.png) [@trych](https://forum.getkirby.com/u/trych)\
**Post date:** [August 25, 2020, 10:39pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/83 "2020-08-25T22:39:47Z")

</div>

I also really would like a cookbook recipe for this. I am familiar with Kirby, learning vue.js and have unfortunately no idea how to set them up together.

---

<div class="post-metadata">

**Author:** ![maxmax](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@maxmax](https://forum.getkirby.com/u/maxmax)\
**Post date:** [January 18, 2021, 5:56pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/84 "2021-01-18T17:56:12Z")

</div>

Hey y’all!

Are there any news on this? I checked the latest link leading to the [getkirby/kql](https://github.com/getkirby/kql) repository. I wanted to try the plugin but it seems like there is no official release yet (January 2021).

I’m also looking for a way to use Kirby with Vue/Nuxt, and when I manage to implement a solution like the KQL plugin, I’m also happy to volunteer for writing a cookbook recipe like @texnixe asked back in May 2020.

Looking fwd hearing from you people!

Cheers  
Max

---

<div class="post-metadata">

**Author:** ![teh](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/teh/32/9669_2.png) [@teh](https://forum.getkirby.com/u/teh)\
**Post date:** [January 18, 2021, 6:19pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/85 "2021-01-18T18:19:57Z")

</div>

I’m using this starterkit at the moment and it’s working great.

> **[johannschopplich/kirby-vue3-starterkit](https://github.com/johannschopplich/kirby-vue3-starterkit)**
>
> ✨ SPA with Vue 3 and Kirby: SEO-friendly, automatic routing, mulit-lang-ready and more!

---

<div class="post-metadata">

**Author:** ![maxmax](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@maxmax](https://forum.getkirby.com/u/maxmax)\
**Post date:** [January 18, 2021, 9:02pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/86 "2021-01-18T21:02:01Z")

</div>

Thx! Will definitely take a look at this 🙂

---

<div class="post-metadata">

**Author:** ![moritzebeling](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/moritzebeling/32/5429_2.png) [@moritzebeling](https://forum.getkirby.com/u/moritzebeling)\
**Post date:** [January 21, 2021, 10:02am UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/87 "2021-01-21T10:02:01Z")

</div>

Over the last year, I only have used Kirby as a headless CMS with the frontend being hosted on Netlify or something. I am really happy with the workflow. My best practice is (until now and open for overthinking that):

1. create global page method like `$page->json()` returning an array of everything that you generally want to know about a page on the frontend
2. create a route like `json/(:any)`, find the requested page and return the array obtained from the `json()` method. eg. `return page( $any )->json()`

- You can extend the `json()` method within single page models.
- You can do the same for `$site`, `$file`, `$pages`, `$files`.
- You can have a parameter like `json( bool $full )` to switch if you want to have a short version of the page data (e.g. only title and url to render a list) or if you want a more detailed dataset including all fields (e.g. for rendering a single page view).
- And you can cache the results within the route.

1. In the frontend you just fetch the `/json/...` api and have your content ready to go.

This is a very simplified approach, without auth or anything, but I like the api result to only include exactly what i need, in a format that already mimics the way i will use the data in the frontend. (Almost like the GraphQL idea)

The only real downside with the complete separation of front- and backend is that you will always have to keep some information about your page in the frontend as well, e.g. some page structure, metadata, slugs or something. Which will thus become unchangeable in the backend.

I don’t know if this is really smart, obvious or stupid 🙂 Just sharing my approach to this.

Ah, and since it’s been a topic: I actually do parse all kirbytext fields on the backend and send the html through the api. I see the spoofing point, but for all projects that don’t handle sensitive user data i think it’s not that relevant. And a frontend kirbytext parser would be way too much overhead.

---

<div class="post-metadata">

**Author:** ![maxmax](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@maxmax](https://forum.getkirby.com/u/maxmax)\
**Post date:** [February 16, 2021, 3:01pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/88 "2021-02-16T15:01:02Z")

</div>

Interesting! So do you use the [JSON Representation approach](https://getkirby.com/docs/cookbook/templating/generating-json) but in a very general way? Could you share some more code? That would be awesome.

---

<div class="post-metadata">

**Author:** ![moritzebeling](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/moritzebeling/32/5429_2.png) [@moritzebeling](https://forum.getkirby.com/u/moritzebeling)\
**Post date:** [February 18, 2021, 3:38pm UTC](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142/89 "2021-02-18T15:38:42Z")

</div>

I mostly do it as follows:

1. Create a page method, e.g. `$page->json()` that returns an array of information about some page:

```auto
/* your Kirby plugin */
'pageMethods' => [
  'json' => function (): array {
    return [
      'title' => $this->title()->value(),
      'path' => $this->id(),
      'template' => $this->intendedTemplate()->name(),
      /* or any other fields that you need */
    ];
  }
]

```

2a. You can already call that `$page->json()` to get that array. For example if you want to use that in some JS on your frontend:

```auto
<!-- snippet/header.php -->
<script>
  let pageData = <?= json_encode( $page->json() ) ?>;
  console.log( pageData );
</script>

```

2b. But maybe you want to fetch that json with JS at a later stage. For that, create a `/json/...` route that returns your array:

```php
'routes' => [
  [
    'pattern' => 'json/(:all)',
    'method' => 'GET',
    'action' => function ( $id ) {
      return page( $id )->json();
    }
  ]
]

```

You can now fetch `site.com/json/page-id` to get your page data.

1. Going from here:

- Use page models to adjust the result of `$page->json()` to a specific content type/template
- Implement some cache inside that route
- Add also `$pages->json()`, `$file->json()`, `$files->json()`, `$site->json()`

⚠ Code not tested, may be stupid, just to demonstrate a possible approach

I am working on a plugin as a boilerplate for that. You can find the current state here, but this is far from it’s final stage: [GitHub - moritzebeling/kirby-headless: Public and customizable Json API Endpoint for Kirby CMS](https://github.com/moritzebeling/kirby-headless)

[Previous page](https://forum.getkirby.com/t/kirby-3-as-headless-cms-for-vue-nuxt/12142.md?page=4)
