NextDrupal Client
A powerful JSON:API client for Drupal.
The NextDrupal
client is a powerful JSON:API client that ships with helpers for working with Drupal data.
You can use the NextDrupal
client to fetch JSON:API data from Drupal to build static pages in advance, or server render pages on-demand.
It also comes with full support for JSON:API write operations which means you can create JSON:API resources from Next.js to Drupal.
Features
- Customizable JSON:API client for data fetching.
- Helpers for fetching resources, menus, views and search indices.
- Helpers for JSON:API write operations (POST, PATCH, and DELETE)
- Support for custom auth (
Bearer
,Basic
,Next-Auth
or bring your own). - Support for custom serializers.
- Support for custom fetcher.
- Support for cached resources (memory cache, redis...etc).
- Human-readable error messages.
Usage
App Router
import { NextDrupal } from "next-drupal"
// Create a new NextDrupal client.const drupal = new NextDrupal("https://example.com")
// Fetch articles.const articles = await drupal.getResourceCollection("node--article")
// Fetch one article by id.const article = await drupal.getResource( "node--article", "f4c61473-8297-4bf3-bab7-21c9633a7ca7")
Pages Router
import { NextDrupalPages } from "next-drupal"
// Create a new DrupalClient.const drupal = new NextDrupalPages("https://example.com")
// Fetch articles.const articles = await drupal.getResourceCollection("node--article")
// Fetch one article by id.const article = await drupal.getResource( "node--article", "f4c61473-8297-4bf3-bab7-21c9633a7ca7")