node-zendesk • Docs
node-zendesk / clients/helpers / assembleUrl
Function: assembleUrl()
assembleUrl(
self
,method
,uri
?):string
Constructs a URL based on the provided method
, uri
, and pre-defined settings within the context.
The function prioritizes query parameters from self.options.get('query')
over other sources. If uri
is an array, the last element can be an object representing query parameters or a query string. If the uri
is a string, it's treated as the URL's endpoint path.
The function also utilizes self.sideLoad
to include side-loaded resources if available. Any conflict in query parameters is resolved with query
taking the highest priority, followed by sideLoad
, and then the provided uri
.
Parameters
• self: object
The context containing options and side-loading settings.
• method: string
The HTTP method. Can be "GET", "PATCH", "POST", "PUT", or "DELETE".
• uri?: (string
| object
)[]
An array representing the URL segments. The last element can be an object of query parameters or a query string.
Returns
string
The assembled URL.
Throws
Will throw an error if self.options
does not implement the 'get' method.
Example
const context = {
options: new Map([['endpointUri', 'http://api.example.com'], ['query', { page: { size: 100 } }]]),
sideLoad: ['comments', 'likes']
};
assembleUrl(context, 'GET', ['users', 'list', '?foo=bar']);
// Expected: "http://api.example.com/users/list.json?foo=bar&include=comments,likes&page[size]=100"
Defined in
clients/helpers.d.ts:32