getArrayOrCsv #
Available since 2.57.0
Gets a parameter from the request arguments as an array, also accepting a comma-separated string.
This is the form the API documents for the ids argument of document:mGet, document:mExists and security:mGetUsers, and for the services argument of server:healthCheck.
- an array is returned as is;
- a string is, with the HTTP protocol only, first parsed as a JSON array (the way to pass an element containing a comma), and otherwise split on
,whatever the protocol.
Unlike getArray, a single value such as ?ids=foo is returned as ["foo"].
Arguments #
getArrayOrCsv (name: string, def?: []): unknown[]| Name | Type | Description |
|---|---|---|
name | string | Parameter name |
def | array | Default value to return if the parameter is not set |
Throws an api.assert.missing_argument error if the parameter is not set and no default value is provided, and an api.assert.invalid_type error if it is neither an array nor a string.
Example #
// GET /_healthcheck?services=storageEngine,memoryStorage
const services = request.getArrayOrCsv('services');
// ["storageEngine", "memoryStorage"]