The hapi plugin ecosystem

We've already seen how easy and useful it can be to integrate third-party libraries in hapi with the usage of blipp and hapi-level in the previous examples. Let's look at the other plugins that are available in the hapi ecosystem. The list I've gathered here is certainly not exhaustive; these are only a few pulled out from the hapijs.com website just to showcase the wide range of plugins available in the ecosystem; for the full list, visit hapijs.com/plugins or visit https://hapi-plugins.com/,a searchable database of hapi plugins.

Authentication

Authentication will be covered in detail in Chapter 5, Securing Applications with Authentication and Authorization, so we won't go into detail on these plugins here, but it's good to be aware that there are plugins in the hapi ecosystem that do the heavy lifting in terms of authentication, such as parsing request headers or cookies. A few of these plugins are as follows:

  • hapi-auth-basic: An authentication scheme for authenticating requests supplied with a username and password combination.
  • hapi-auth-cookie: An authentication scheme that provides simple cookie-based session management.
  • bell: A third-party logic plugin that ships with support for authentication with a third-party service such as GitHub, Twitter, or Facebook.

Documentation generation

Documentation is always a painful part of development. It doubles the work of the developer, as they must write code and the matching documentation. Keeping the two in sync is often painful. I find that if at any stage in the development cycle, you have to repeat yourself, you're usually doing something unnecessary, and the following plugin proves that. When registered, it generates documentation based on route configuration:

  • hapi-swagger: A documentation generation plugin. It self-documents all APIs based on the supplied route configuration with interactive swagger documentation.

Logging

For production systems, logging is of the utmost importance, and unfortunately, is often neglected until too late. The following plugins make logging for hapi servers much easier:

  • blipp: We have seen this one already; it displays the routing table on server start.
  • good: A logging plugin that supports multiple outputs. We will cover this plugin in more detail in Chapter 7, Making Your Application Production Ready.

Utilities

These are extra plugins from the hapi universe that demonstrate the flexibility and power of hapi's plugin system:

  • inert: The file handler plugin we looked at in Chapter 2, Adding Functionality by Routing Requests
  • vision: The template rendering support plugin that we looked at in Chapter 2, Adding Functionality by Routing Requests
  • nes: A websocket adapter plugin for hapi for building real-time applications with hapi
  • h2o2: A proxy handler plugin
  • bassmaster: This adds a batch endpoint that makes it easy to combine multiple requests into a single one
  • tv: An interactive debug console plugin for hapi servers

These are just a few plugins; there are many more, and I encourage you to take a look now and experiment with them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.249.220