buildEndpoint
Get the JSON:API entry for a resource type.
const url = await drupal.buildEndpoint({ locale, resourceType, path, searchParams}): Promise<string>type: string- Optional
- The resource type. Example:
node--article.
locale: string- Optional
- The locale to fetch the index. Example:
esorfr.
path: string- Optional
- The path to fetch. Example:
test.
searchParams: string | Record<string, string> | URLSearchParams | JsonApiParams- Optional
- Search params. Example:
{ bar: "baz" }.
Notes
By default, when retrieving resources in getResource or getResourceCollection, the NextDrupal client make a request to Drupal to fetch the JSON:API resource entry.
Example: if you provide node--article, NextDrupal will make a request to http://example.com/jsonapi/node/article.
If you would like to infer the entry from the resource type, use the useDefaultResourceTypeEntry option.
const drupal = new DrupalClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, { useDefaultResourceTypeEntry: true,})Examples
// https://example.com/jsonapi/node/article.const url = await drupal.buildEndpoint({ resourceType: `node--article` })
// https://example.com/jsonapi/en/node/article.const url = await drupal.buildEndpoint({ locale: `en`, resourceType: `node--article`,})
// https://example.com/jsonapi/en/node/article?include=field_image.const url = await drupal.buildEndpoint({ locale: `en`, resourceType: `node--article`, searchParams: `include=field_image`,})
// https://example.com/jsonapi/en/views/articles/page_1.const url = await drupal.buildEndpoint({ locale: `en`, path: `/views/articles/page_1`,})