Skip to content

Commit 63d1e3b

Browse files
committed
docs: add reference examples to buildUrl
1 parent 2015920 commit 63d1e3b

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,35 @@ export class NextDrupalBase {
269269
/**
270270
* Builds a URL with the given path and search parameters.
271271
*
272-
* @param {string} path The URL path.
273-
* @param {EndpointSearchParams} searchParams The search parameters.
272+
* @param {string} path The path for the url. Example: "/example"
273+
* @param {string | Record<string, string> | URLSearchParams | JsonApiParams} searchParams Optional query parameters.
274274
* @returns {URL} The constructed URL.
275+
* @example
276+
* ```ts
277+
* const drupal = new DrupalClient("https://example.com")
278+
*
279+
* // https://drupal.org
280+
* drupal.buildUrl("https://drupal.org").toString()
281+
*
282+
* // https://example.com/foo
283+
* drupal.buildUrl("/foo").toString()
284+
*
285+
* // https://example.com/foo?bar=baz
286+
* client.buildUrl("/foo", { bar: "baz" }).toString()
287+
* ```
288+
*
289+
* Build a URL from `DrupalJsonApiParams`
290+
* ```ts
291+
* const params = {
292+
* getQueryObject: () => ({
293+
* sort: "-created",
294+
* "fields[node--article]": "title,path",
295+
* }),
296+
* }
297+
*
298+
* // https://example.com/jsonapi/node/article?sort=-created&fields%5Bnode--article%5D=title%2Cpath
299+
* drupal.buildUrl("/jsonapi/node/article", params).toString()
300+
* ```
275301
*/
276302
buildUrl(path: string, searchParams?: EndpointSearchParams): URL {
277303
const url = new URL(path, this.baseUrl)

0 commit comments

Comments
 (0)