What is a plugin?
A Fastify plugin is a component that allows developers to extend and add functionalities to their server applications. Some of the most common use cases for developing a plugin are handling a database connection or extending default capabilities – for example, to request parsing or response serialization.
Thanks to their unique properties, plugins are the basic building blocks of our application. Some of the most prominent properties are the following:
- A plugin can register other plugins inside it.
- A plugin creates, by default, a new scope that inherits from the parent. This behavior also applies to its children and so on, although using the parent’s context is still possible.
- A plugin can receive an
options
parameter that can be used to control its behavior, construction, and reusability. - A plugin can define scoped and prefixed routes, making it the perfect router.
At this point, it should be clear that where other frameworks...