Skip to content

Druxt

The core module, DruxtClient, DruxtStore and the DruxtModule base component.

Druxt: the core client, store and DruxtModule base

npm dev CI Known Vulnerabilities codecov

The core druxt package is the foundation every other Druxt module builds on. It provides the three pieces the whole framework shares:

  • DruxtClient: the Drupal JSON:API communication layer.
  • DruxtStore: the Vuex module caching resources and collections for all modules.
  • DruxtModule: the base component behind the theme-component suggestion system.

Installation

  1. Install the package:

    npm i druxt
    
  2. Add the module and your backend URL to nuxt.config.js:

    export default {
      modules: [['druxt', { baseUrl: 'https://api.umami.demo.druxtjs.org' }]],
    };
    

    * Replace https://api.umami.demo.druxtjs.org with your own Drupal backend.

  3. On the Drupal side, install and enable the Druxt module and grant the access druxt resources permission to the relevant roles. Missing this is the most common cause of site-wide JSON:API failures. See Troubleshooting if requests are failing after install.

Development releases

Every change merged to develop is published under the dev tag:

npm i druxt@dev

These are unreleased builds. See development releases before using one.

Compatibility

As of September 2026. See the releases for the current version.

Supported
Nuxt2.15 or later (Nuxt 2 line). Nuxt 3 is not supported.
Vue2.7
Node16, the tested version. Node 16 is past upstream end of life. The 1.x line targets it deliberately. 17 and later need NODE_OPTIONS=--openssl-legacy-provider to build.
Drupal core10 or 11. drupal/druxt 1.2.2 declares ^10 || ^11 || ^12 and ended 8 and 9 support. 12 is declared but waits on Decoupled Router and JSON:API Menu Items. Tested against 10 and 11.
Drupal moduledrupal/druxt ^1.2.2, which brings decoupled_router, jsonapi_menu_items and jsonapi_views. Earlier 1.2.x releases are incompatible with Decoupled Router 2.0.7 (#3618675).
Known pins@nuxtjs/storybook 4.2.0 (later majors need Nuxt 3). Axios 0.x, or add it to build.transpile

What these bounds promise over time is stated in the support and versioning policy.

Translated routes also need a decoupled_router patch; see the multilingual guide.

Settings

OptionTypeDefaultDescription
baseUrlstringThe Drupal backend URL. Required.
endpointstring'/jsonapi'The JSON:API endpoint path.
proxy.apibooleanfalseProxy API requests via Nuxt (guide).
proxy.filesboolean|stringfalseProxy Drupal files. A string sets the site.
cacheboolean|object{}The server cache, see below. false turns it off.

See the Nuxt module API for the full options list.

Server cache

In production, the server keeps Drupal's responses between requests for as long as Drupal's Cache-Control header allows. It keeps the JSON:API index and menus, and with cache.content every other response Druxt fetches, as Caching content describes. Drupal sets that header from the page cache maximum age (Administration > Configuration > Development > Performance). At the default of 0, nothing is kept. A request with an Authorization header or a Drupal session cookie never reads or fills the cache. The cache is off under nuxt dev.

OptionTypeDefaultDescription
cache.contentbooleanfalseAlso keep entities, collections, views and route lookups.
cache.maxSizenumber52428800 (50 MB)Bytes of responses kept per cache area. The least recently used go.
cache.ttlnumberSeconds a response may be kept at most. 0 keeps nothing.
cache.secretstringTurns on POST /_druxt/cache/clear.
cache.sessionCookiestring'S?SESS[0-9a-f]+'A pattern for the session cookie name, for a proxy that renames it.

Clear the cache from the app with this.$store.dispatch('druxt/clearCache'), or from Drupal by sending POST /_druxt/cache/clear with the secret in an X-Druxt-Secret header. Each Nuxt process has its own cache, so a site with several processes clears each one.

The endpoint is server middleware, so list Druxt, or the module that adds it such as druxt-site, under modules. Nuxt runs buildModules only while it builds, so under nuxt start the endpoint would answer 404.

Caching content

cache.content extends the cache to every other request Druxt sends Drupal: entities, collections, views and route lookups. A second visitor to a page then costs Drupal nothing until the page's lifetime runs out.

// nuxt.config.js
export default {
  druxt: {
    cache: { content: true, secret: process.env.DRUXT_CACHE_SECRET },
  },
};

Content changes far more often than menus, so pair it with a clear from Drupal, below. Without one, an edit reaches anonymous visitors only once the page cache maximum age has passed. Only successful responses are kept, so a page published after a visitor saw a 404 appears straight away. A bypassCache dispatch to the Druxt store also skips this cache and stores the fresh response.

cache.maxSize counts the bytes of the stored JSON, and it applies to each cache area and consumer. A full cache can take about three times that in server memory, so size it against the memory each Nuxt process has. A response larger than the whole limit is not kept.

Clearing from Drupal with Purge

The Purge module can send that request whenever content changes. Enable purge, purge_purger_http, purge_queuer_coretags and a processor such as purge_processor_lateruntime, then add the bundled HTTP purger:

drush p:purger-add httpbundled

Give it the method POST, the Nuxt host and port, the path /_druxt/cache/clear, a header X-Druxt-Secret with the secret, and the invalidation type tag. One save then costs one request, whatever it invalidates, and a request refused for a wrong secret is sent again with the next batch. Keep the secret out of exported configuration: set it from settings.php as a $config override.

DruxtClient

The client is the communication layer between your application and Drupal's JSON:API: resources, collections, indexing and authentication all flow through it.

import { DruxtClient } from 'druxt';

const client = new DruxtClient('https://api.umami.demo.druxtjs.org');
const collection = await client.getCollection('node--article');

DruxtStore

The Vuex module that all Druxt modules share: request deduplication, the resource/collection cache, and include handling.

const resource = await this.$store.dispatch('druxt/getResource', {
  type: 'node--article',
  id: 'd8dfd355-7f2f-4fc3-a149-288e4e293bdd',
});

DruxtModule

The base component for all Druxt components: it turns a druxt() options object (component suggestions, props, slots) into themeable rendering. Building on it is covered by the custom module tutorial, and the mechanism by Component resolution.

Where to go next


Modules



Support

Druxt is an open-source project, built by the community for the community.

Find support or get involved in building Druxt via the community channels:


Contributing

Open in DevPod!

See the Contributing guide.


License

MIT


Note: The contents of this file were automatically generated from the packages/druxt/README.md.