1.3.2 • Published 4 years ago
@dukai.net/hapi-settings v1.3.2
hapi-settings
Helper plugin provide toolkit support to retrieve objects from application settings.
Install:
npm install @dukai.net/hapi-settings
or:
yarn add @dukai.net/hapi-settings
Use:
path: '/api/v1/orange/{id}',
method: 'GET',
handler: async (request, h) => {
try {
const dal = h.dal(request); // Returns with the DAL object, which gives access to all repository object
const args = h.args(request); // Combines all input from params, query and payload to a single object
// do something with db object here
return await dal.orange.getSomething(args);
} catch (err) {
return boom.boomify(err, { statusCode: 400 });
}
},
All available methods:
// Under the hood the toolkit methods accessing the "request.server.settings.app" object where custom data stored
const dal = h.dal(request); // Data Access Layer object with all the repositories from all the plugins
const args = h.args(request); // Combines all input from params, query and payload to a single object
const plugins = h.plugins(request); // Returns the array of plugin names
const settings = h.settings(request); // Returns the object holding the above objects as well