Build fluency in Fastify's plugin model, hooks, and schema-first design.
0 / 5 completed
1 / 5
During a code review, a plugin's decorators leak into the parent scope unexpectedly. What Fastify concept governs this?
Fastify plugins create an encapsulated context by default, so decorators and hooks registered inside stay local. To deliberately share across scopes you wrap with fastify-plugin to break encapsulation. Misunderstanding this is the usual cause of leaks or missing decorators.
2 / 5
At standup, a dev wants to run code before validation on every request. Which Fastify mechanism fits?
Fastify hooks like onRequest and preValidation run at defined lifecycle points. They let you add cross-cutting logic such as auth or logging. Choosing the right hook stage controls when your code runs relative to validation.
3 / 5
In a design review, the team wants to attach a reusable method to the request object. Which Fastify API?
A decorator added via decorateRequest attaches a property or method to every request instance efficiently. Fastify pre-allocates the shape for performance. This is the idiomatic way to share helpers like a current user.
4 / 5
During a PR review, a dev defines JSON Schemas for body and response. What benefit does Fastify gain?
Fastify is schema-first: declaring JSON Schemas drives input validation and compiles a fast serializer for responses. This both rejects bad input and speeds up output serialization. It is central to Fastify's performance story.
5 / 5
In a code review, a TypeScript dev wants schemas to infer route handler types. Which Fastify v5 feature helps?
Fastify type providers (e.g. for TypeBox or Zod) bridge runtime JSON Schemas to static TypeScript types. With a provider configured, handler request and reply types are inferred from the route schema. This gives end-to-end type safety without duplicating definitions.