buildUrl
用于构建包含查询参数的 URL 的辅助函数。
const url = drupal.buildUrl(path, params?): URL
path: string
- 必需
- URL 的路径。例如:"/example"
params: string | Record<string, string> | URLSearchParams | JsonApiParams
- 可选
示例
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()
- 从
DrupalJsonApiParams
构建 URL
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()