Instantiates a new NextDrupalPages.
const client = new NextDrupalPages(baseUrl)
The baseUrl of your Drupal site. Do not add the /jsonapi suffix.
Options for the client. See Experiment_DrupalClientOptions.
Optional
accessOptional
cacheOptional
fetcherOptional
init: RequestInitGets static paths from the context.
The types of the resources.
The static paths context.
Optional
options: { params?: JsonApiParams; pathPrefix?: string } & JsonApiWithAuthOptionOptions for the request.
The fetched static paths.
Adds a locale prefix to the given path.
The path.
The options for adding the locale prefix.
Optional
defaultLocale?: stringThe default locale.
Optional
locale?: stringThe locale.
The path with the locale prefix.
Builds an endpoint URL for the specified parameters.
The parameters for the endpoint.
The built endpoint URL.
Builds static paths from resources.
The resources.
Optional
options: { locale?: string; pathPrefix?: string }Options for the request.
The built static paths.
Builds static paths parameters from paths.
The paths.
Optional
options: { locale?: string; pathPrefix?: string }Options for the request.
The built static paths parameters.
Builds a URL with the given path and search parameters.
The URL path.
Optional
searchParams: EndpointSearchParamsThe search parameters.
The constructed URL.
Constructs a path from the given segment and options.
The path segment.
The options for constructing the path.
Optional
defaultLocale?: stringThe default locale.
Optional
locale?: stringThe locale.
Optional
pathPrefix?: stringThe path prefix.
The constructed path.
Creates a new file resource for the specified media type.
The type of the media.
The body of the file resource.
Optional
options: JsonApiOptions & JsonApiWithNextFetchOptionsOptions for the request.
The created file resource.
Creates a new resource of the specified type.
The type of the resource.
The body of the resource.
Optional
options: JsonApiOptions & JsonApiWithNextFetchOptionsOptions for the request.
The created resource.
Deletes an existing resource of the specified type.
The type of the resource.
The UUID of the resource.
Optional
options: JsonApiOptions & JsonApiWithNextFetchOptionsOptions for the request.
True if the resource was deleted, false otherwise.
Fetches a resource from the given input URL or path.
The input URL or path.
The fetch options.
The fetch response.
Gets an access token using the provided client ID and secret.
Optional
clientIdSecret: NextDrupalAuthClientIdSecretThe client ID and secret.
The access token.
Gets the authentication configuration from the context and options.
The static props context.
Options for the request.
The authentication configuration.
Gets the authorization header value based on the provided auth configuration.
The auth configuration.
The authorization header value.
Extracts errors from the fetch response.
The fetch response.
The extracted errors.
Fetches the JSON:API index.
Optional
locale: stringThe locale for the request.
Optional
options: JsonApiWithNextFetchOptionsOptions for the request.
The JSON:API index.
Fetches a menu by its name.
The name of the menu.
Optional
options: JsonApiOptions & JsonApiWithCacheOptions & JsonApiWithNextFetchOptionsOptions for the request.
The fetched menu.
Fetches a resource of the specified type by its UUID.
The resource type. Example: node--article
, taxonomy_term--tags
, or block_content--basic
.
The id of the resource. Example: 15486935-24bf-4be7-b858-a5b2de78d09d
.
Optional
options: JsonApiOptions & JsonApiWithCacheOptions & JsonApiWithNextFetchOptionsOptions for the request.
The fetched resource.
Get a page by uuid.
const node = await drupal.getResource(
"node--page",
"07464e9f-9221-4a4f-b7f2-01389408e6c8"
)
Get the es translation for a page by uuid.
const node = await drupal.getResource(
"node--page",
"07464e9f-9221-4a4f-b7f2-01389408e6c8",
{
locale: "es",
defaultLocale: "en",
}
)
Get the raw JSON:API response.
const { data, meta, links } = await drupal.getResource(
"node--page",
"07464e9f-9221-4a4f-b7f2-01389408e6c8",
{
deserialize: false,
}
)
Get a node--article resource using cache.
const id = "07464e9f-9221-4a4f-b7f2-01389408e6c8"
const article = await drupal.getResource("node--article", id, {
withCache: true,
cacheKey: `node--article:${id}`,
})
Get a page resource with time-based revalidation.
const node = await drupal.getResource(
"node--page",
"07464e9f-9221-4a4f-b7f2-01389408e6c8",
{ next: { revalidate: 3600 } }
)
Get a page resource with tag-based revalidation.
const {slug} = params;
const path = drupal.translatePath(slug)
const type = path.jsonapi.resourceName
const tag = `${path.entity.type}:${path.entity.id}`
const node = await drupal.getResource(path, path.entity.uuid, {
params: params.getQueryObject(),
tags: [tag]
})
Using DrupalNode for a node entity type.
import { DrupalNode } from "next-drupal"
const node = await drupal.getResource<DrupalNode>(
"node--page",
"07464e9f-9221-4a4f-b7f2-01389408e6c8"
)
Using DrupalTaxonomyTerm for a taxonomy term entity type.
import { DrupalTaxonomyTerm } from "next-drupal"
const term = await drupal.getResource<DrupalTaxonomyTerm>(
"taxonomy_term--tags",
"7b47d7cc-9b1b-4867-a909-75dc1d61dfd3"
)
Fetches a resource of the specified type by its path.
The path of the resource.
Optional
options: { isVersionable?: boolean } & JsonApiOptions & JsonApiWithNextFetchOptionsOptions for the request.
The fetched resource.
Fetches a collection of resources of the specified type.
The type of the resources.
Optional
options: { deserialize?: boolean } & JsonApiOptions & JsonApiWithNextFetchOptionsOptions for the request.
The fetched collection of resources.
Gets a collection of resources from the context.
The type of the resources.
The static props context.
Optional
options: { deserialize?: boolean } & JsonApiOptionsOptions for the request.
The fetched collection of resources.
Fetches path segments for a collection of resources of the specified types.
The types of the resources.
Optional
options: { params?: JsonApiParams; pathPrefix?: string } & JsonApiWithAuthOption & (Options for the request.
The fetched path segments.
Gets a resource from the context.
The input path or translated path.
The static props context.
Optional
options: { isVersionable?: boolean; pathPrefix?: string } & JsonApiOptionsOptions for the request.
The fetched resource.
Fetches a search index by its name.
The name of the search index.
Optional
options: JsonApiOptions & JsonApiWithNextFetchOptionsOptions for the request.
The fetched search index.
Gets a search index from the context.
The name of the search index.
The static props context.
Optional
options: JsonApiOptionsOptions for the request.
The fetched search index.
Gets static paths from the context.
The types of the resources.
The static paths context.
Optional
options: { params?: JsonApiParams; pathPrefix?: string } & JsonApiWithAuthOptionOptions for the request.
The fetched static paths.
Fetches a view by its name.
The name of the view.
Optional
options: JsonApiOptions & JsonApiWithNextFetchOptionsOptions for the request.
The fetched view.
Handles preview mode.
The API request.
The API response.
Optional
options: { enable: boolean }Options for the request.
Translates a path to a DrupalTranslatedPath object.
The path to translate.
Optional
options: JsonApiWithAuthOption & JsonApiWithNextFetchOptionsOptions for the request.
The translated path.
Translates a path from the context.
The static props context.
Optional
options: { pathPrefix?: string } & JsonApiWithAuthOptionOptions for the request.
The translated path.
Updates an existing resource of the specified type.
The type of the resource.
The UUID of the resource.
The body of the resource.
Optional
options: JsonApiOptions & JsonApiWithNextFetchOptionsOptions for the request.
The updated resource.
The NextDrupalPages class extends the NextDrupal class and provides methods for interacting with a Drupal backend in the context of Next.js pages.