toys
The hapi utility toy chest
Lead Maintainer - Devin Ivy
Usage
See also the API Reference
Toys is a collection of utilities made to reduce common boilerplate in hapi v17+ projects, aid usage of events and streams in async
functions (e.g. handlers and server methods), and provide versions of widely-used utilities from Hoek optimized to perform well in hot code paths such as route handlers.
Below is an example featuring Toys.auth.strategy()
, Toys.reacher()
, and Toys.withRouteDefaults()
. The API Reference is also filled with examples.
const Hapi = ;const Boom = ;const Toys = ; async { const server = Hapi; // Make a one-off auth strategy for testing Toysauth; // Make function to efficiently index into a request to grab an authed user's name const grabAuthedUsername = Toys; // Default all route methods to "get", unless otherwise specified const defaultToGet = Toys; server; await serverstart; console;};