class-validator
To validate request body, request headers and URL query, specify a class with class-validator instead of type for reqBody, reqHeaders and query.
Deprecated after 0.30.0
After frourio
and frourio-express
version 0.30.0
, using class-validator as a validator in Frourio is deprecated.
If used, a warning will be displayed during the build. Consider migrating to zod.
Example
Passing Validator Options
- Fastify
- Express
server/service/app.ts
import Fastify, { FastifyServerFactory } from 'fastify';
import server from '$/$server';
export const init = (serverFactory?: FastifyServerFactory) => {
const app = Fastify({ serverFactory });
server(app, { basePath: '/api', validator: { whitelist: true } });
return app;
};
server/service/app.ts
import express from 'express';
import server from '$/$server';
export const init = () => {
const app = express();
server(app, { basePath: '/api', validator: { whitelist: true } });
return app;
};