Recipes
Migrating from Fastify
Fastify concepts (schemas, hooks, plugins, decorators) mapped to Kest.
Fastify and Kest share a philosophy: speed, structure and validation up front. Kest runs on Netty and can be benchmarked against Fastify-style workloads (see Benchmarks).
| Fastify | Kest |
|---|---|
fastify.get('/x', { schema }, handler) | @Get("/x") on a controller method; the request class carries the constraints |
| JSON Schema for body, query, params | constraint annotations (@NotBlank, @Min, @Pattern, @Email...), checked by ValidationPipe |
| Response schema (fast serialization) | return a typed value; @Exclude/@Expose shape it |
fastify.register(plugin) and encapsulation | @Module with imports, providers, exports |
fastify.decorate('db', db) | a provider injected through the constructor |
Hooks: onRequest, preHandler | Middleware (before routing), Guard, Pipe |
Hooks: onSend, onResponse | Interceptor (after the handler) |
onError, setErrorHandler | ExceptionFilter, @ControllerAdvice |
fastify-cors, @fastify/helmet, @fastify/compress | enableCors, useSecurityHeaders, useCompression |
@fastify/jwt | JwtModule, @Authenticated |
@fastify/static | serveStatic |
@fastify/multipart | @FormFile |
@fastify/rate-limit | throttler |
@fastify/swagger | api-docs |
pino | Logger (it has a JSON mode, see Logging.configure) |
app.inject() for tests | Testing.createModule<AppModule> and startHttp(...) |
| HTTP/2 option | NettyHttpAdapter(port, http2 = true) |
Differences to expect
- Validation is not JSON Schema. Constraints are annotations; there is no schema object to share with other tools. For documentation,
api-docsproduces OpenAPI from the same classes. - Plugins do not encapsulate by prefix. Modules group providers; every provider is visible to every module (the build still checks that dependencies exist). Use
setGlobalPrefixor a controller path for URL prefixes. - Async hooks become plain functions running on virtual threads.
Steps
- One controller per route prefix; one module per plugin.
- Turn decorated values (
fastify.decorate) into injectable providers. - Replace hooks according to the table: authentication becomes a guard, response shaping an interceptor.
- Replace route schemas with request classes carrying constraint annotations.