Skip to content

Commit 32d40b1

Browse files
committed
docs: add examples for getResourceByPath
1 parent 1509e09 commit 32d40b1

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

packages/next-drupal/src/next-drupal.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,32 @@ export class NextDrupal extends NextDrupalBase {
431431
/**
432432
* Fetches a resource of the specified type by its path.
433433
*
434-
* @param {string} path The path of the resource.
435-
* @param {JsonApiOptions & JsonApiWithNextFetchOptions} options Options for the request.
434+
* @param {string} path The path of the resource. Example: `/blog/slug-for-article`.
435+
* @param { { isVersionable?: boolean } & JsonApiOptions & JsonApiWithNextFetchOptions} options Options for the request.
436+
* - isVersionable: Set to true if you're fetching the revision for a resource. Automatically set to true for node entity types
436437
* @returns {Promise<T>} The fetched resource.
438+
* @requires Decoupled Router module
439+
* @example
440+
* Get a page by path
441+
* ```
442+
* const node = await drupal.getResourceByPath("/blog/slug-for-article")
443+
* ```
444+
* Get the raw JSON:API response
445+
* ```
446+
* const { data, meta, links } = await drupal.getResourceByPath(
447+
* "/blog/slug-for-article",
448+
* {
449+
* deserialize: false,
450+
* }
451+
* )
452+
*```
453+
* Using DrupalNode for a node entity type
454+
* ```
455+
* import { DrupalNode } from "next-drupal"
456+
* const node = await drupal.getResourceByPath<DrupalNode>(
457+
* "/blog/slug-for-article"
458+
* )
459+
* ```
437460
*/
438461
async getResourceByPath<T extends JsonApiResource>(
439462
path: string,

0 commit comments

Comments
 (0)