getResourceCollection
Fetch a collection of resources.
const resource = await drupal.getResourceCollection<T = JsonApiResource[]>( type, options?: { params, withAuth, deserialize, locale, defaultLocale, }): Promise<T>
type: string
- Required
- The resource type. Example:
node--article
oruser--user
.
options
- Optional
params: JsonApiParams
: JSON:API params such asfilter
,fields
,include
orsort
.withAuth: boolean | DrupalClientAuth
:- Set the authentication method to use. See the authentication docs.
- Set to
true
to use the authentication method configured on the client.
deserialize: boolean
: Set to false to return the raw JSON:API response.locale: string
: The locale to fetch the resource in.defaultLocale: string
: The default locale of the site.
Examples
- Get all articles.
const articles = await drupal.getResourceCollection("node--article")
- Using filters.
const publishedArticles = await drupal.getResourceCollection("node--article", { params: { "filter[status]": "1", },})
- Get the raw JSON:API response.
const { data, meta, links } = await drupal.getResourceCollection("node--page", { deserialize: false,})
TypeScript
- Using
DrupalNode
for a node entity type.
import { DrupalNode } from "next-drupal"
const nodes = await drupal.getResourceCollection<DrupalNode[]>("node--article")
See the TypeScript docs for more built-in types.