buildUrl

A helper for building Url with query params.


const url = drupal.buildUrl(path, searchParams?): URL
  • path: string
    • Required
    • The path for the url. Example: "/example"
  • searchParams: string | Record<string, string> | URLSearchParams | JsonApiParams
    • Optional

Examples

const drupal = new DrupalClient("https://example.com")
// https://drupal.org
drupal.buildUrl("https://drupal.org").toString()
// https://example.com/foo
drupal.buildUrl("/foo").toString()
// https://example.com/foo?bar=baz
client.buildUrl("/foo", { bar: "baz" }).toString()
  • Build a URL from DrupalJsonApiParams
const params = {
getQueryObject: () => ({
sort: "-created",
"fields[node--article]": "title,path",
}),
}
// https://example.com/jsonapi/node/article?sort=-created&fields%5Bnode--article%5D=title%2Cpath
drupal.buildUrl("/jsonapi/node/article", params).toString()