| name | fastify |
| description | Guides AI agents to write correct, idiomatic Fastify code using plugins, routes, schemas, and lifecycle hooks. |
| metadata | {"tags":["fastify","nodejs","http","api"]} |
Fastify Skill
Use this skill when writing or reviewing any Fastify server code: route definitions, plugins, request validation, error handling, or server lifecycle.
When to Use
- Creating a Fastify server or adding routes
- Writing or registering a Fastify plugin
- Defining request/reply JSON schemas
- Handling errors and reply serialization
- Using hooks (
onRequest, preHandler, onSend, etc.)
- Decorating the Fastify instance or request/reply objects
Rules
- rules/plugins.md — Plugin authoring,
fastify-plugin, encapsulation, registration order.
- rules/routes.md — Route definitions, shorthand methods, async handlers, reply usage.
- rules/schemas.md — JSON Schema for request validation and reply serialization with
$ref.
- rules/hooks.md — Lifecycle hooks, execution order, and correct async usage.
- rules/error-handling.md —
setErrorHandler, httpErrors, and safe error propagation.
Quick Reference
import Fastify from 'fastify';
const app = Fastify({ logger: true });
app.register(import('./routes/users.js'));
await app.listen({ port: 3000, host: '0.0.0.0' });
app.post('/users', {
schema: {
body: { $ref: 'CreateUserBody#' },
response: { 201: { $ref: 'User#' } },
},
handler: async (request, reply) => {
const user = await createUser(request.body);
return reply.code(201).send(user);
},
});