Skip to main content


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.



import { MinLength, IsString } from 'class-validator';

export class LoginBody {
id: string;

pass: string;

export class TokenHeader {
token: string;

API Definition

import { LoginBody, TokenHeader } from '$/validators';

export type Methods = {
post: {
reqBody: LoginBody;
resBody: {
token: string;

delete: {
reqHeaders: TokenHeader;


$ curl -X POST -H "Content-Type: application/json" -d '{"id":"correctId","pass":"correctPass"}' http://localhost:8080/api/token

$ curl -X POST -H "Content-Type: application/json" -d '{"id":"abc","pass":"12345"}' http://localhost:8080/api/token -i
HTTP/1.1 400 Bad Request

$ curl -X POST -H "Content-Type: application/json" -d '{"id":"incorrectId","pass":"incorrectPass"}' http://localhost:8080/api/token -i
HTTP/1.1 401 Unauthorized

Passing Validator Options

class-validator options

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;