getId #
Available since 2.11.0
Returns the _id
specified in the request.
Arguments #
getId (
options: {
ifMissing?: 'error' | 'generate' | 'ignore',
generator?: () => string,
} = { generator: uuid.v4, ifMissing: 'error' }
): string
Options:
Name | Type | Description |
---|---|---|
ifMissing | 'error' | 'generate' |
generator | () => string | Function used to generate an ID |
Example #
const id = request.getId();
// equivalent
const id = request.input.args._id;
//+ checks to make sure that "_id" is of the right type
// and throw standard API error when it's not the case
// generate a default ID if it's missing
const id = request.getId({ ifMissing: "generate" });
Edit this page on Github(opens new window)