Fastify is one of the fastest Node.js web frameworks — but its plugin system, schema validation, and hooks make it far more powerful than a simple HTTP server.
Plugin Architecture
Fastify's encapsulated plugin system is its killer feature:
import Fastify from " fastify "
const app = Fastify ({ logger : true })
// Register a plugin with encapsulated scope app . register ( async function userRoutes ( fastify ) { // This decorator is only visible inside this plugin fastify . decorate ( " userService " , new UserService ())
fastify . get ( " /users " , async ( request ) => { return fastify . userService . findAll ( request . query ) })
fastify . get ( " /users/:id " , async ( request ) => { return fastify . userService . findById ( request . params . id ) })
fastify . post ( " /users " , async ( request , reply ) => { const user = await fastify . userService . create ( request . body ) reply . code ( 201 ). send ( user ) }) }, { prefix : " /api/v1 " })
await app .…