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.orgdrupal.buildUrl("https://drupal.org").toString()
// https://example.com/foodrupal.buildUrl("/foo").toString()
// https://example.com/foo?bar=bazclient.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%2Cpathdrupal.buildUrl("/jsonapi/node/article", params).toString()