Skip to content
druxt-druxt

Druxt

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

Druxt

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. Download the module:

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

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

    * Replace https://demo-api.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.

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.

See the Nuxt module API for the full options list.

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://demo-api.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


Package README

The full npm package README (features, badges, install) is mirrored as the generated package README page.