Skip to content

Commit

Permalink
docs: add examples for getResourceByPath
Browse files Browse the repository at this point in the history
  • Loading branch information
backlineint committed Jan 24, 2025
1 parent 1509e09 commit 32d40b1
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions packages/next-drupal/src/next-drupal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,32 @@ export class NextDrupal extends NextDrupalBase {
/**
* Fetches a resource of the specified type by its path.
*
* @param {string} path The path of the resource.
* @param {JsonApiOptions & JsonApiWithNextFetchOptions} options Options for the request.
* @param {string} path The path of the resource. Example: `/blog/slug-for-article`.
* @param { { isVersionable?: boolean } & JsonApiOptions & JsonApiWithNextFetchOptions} options Options for the request.
* - isVersionable: Set to true if you're fetching the revision for a resource. Automatically set to true for node entity types
* @returns {Promise<T>} The fetched resource.
* @requires Decoupled Router module
* @example
* Get a page by path
* ```
* const node = await drupal.getResourceByPath("/blog/slug-for-article")
* ```
* Get the raw JSON:API response
* ```
* const { data, meta, links } = await drupal.getResourceByPath(
* "/blog/slug-for-article",
* {
* deserialize: false,
* }
* )
*```
* Using DrupalNode for a node entity type
* ```
* import { DrupalNode } from "next-drupal"
* const node = await drupal.getResourceByPath<DrupalNode>(
* "/blog/slug-for-article"
* )
* ```
*/
async getResourceByPath<T extends JsonApiResource>(
path: string,
Expand Down

0 comments on commit 32d40b1

Please sign in to comment.