Using a custom fetcher with DrupalClient.

The DrupalClient uses the polyfilled fetch from Next.js as the default fetcher.

You can provide your own using the fetcher option.


Here's how you can replace the default fetcher with cross-fetch.

We're using cross-fetch instead of node-fetch because it is compatible with the built-in fetch and uses the same signature.


import { DrupalClient } from "next-drupal"
import crossFetch from "cross-fetch"
// Create a custom fetcher.
const customFetcher = (url, options) => {
const { withAuth, ...opts } = options
if (withAuth) {
// Make additional requests to fetch a bearer token
// Or any other Authorization headers.
return crossFetch(url, {
// Pass in additional options. Example: agent.
// Pass the custom fetcher to the client.
export const drupal = new DrupalClient(
fetcher: customFetcher,