Skip to content

Commit ace7dac

Browse files
committed
docs: add reference examples to fetch
1 parent 63d1e3b commit ace7dac

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,21 @@ export class NextDrupalBase {
179179
/**
180180
* Fetches a resource from the given input URL or path.
181181
*
182-
* @param {RequestInfo} input The input URL or path.
183-
* @param {FetchOptions} init The fetch options.
182+
* @param {RequestInfo} input The url to fetch from.
183+
* @param {FetchOptions} init The fetch options with `withAuth`.
184+
* If `withAuth` is set, `fetch` will fetch an `Authorization` header before making the request.
184185
* @returns {Promise<Response>} The fetch response.
186+
* @remarks
187+
* To provide your own custom fetcher, see the fetcher docs.
188+
* @example
189+
* ```ts
190+
* const url = drupal.buildUrl("/jsonapi/node/article", {
191+
* sort: "-created",
192+
* "fields[node--article]": "title,path",
193+
* })
194+
*
195+
* const response = await drupal.fetch(url.toString())
196+
* ```
185197
*/
186198
async fetch(
187199
input: RequestInfo,

0 commit comments

Comments
 (0)