Validation in Moost
Moost validates handler input through its pipes pipeline, with DTOs and rules authored in Atscript — annotated .as types that emit a validator() factory at build time. The @atscript/moost-validator package plugs that validator into Moost as a pipe, so request bodies, params, and DI values are checked before your handler runs.
Quick start
ts
import { Moost } from 'moost'
import { MoostHttp } from '@moostjs/event-http'
import { validatorPipe, validationErrorTransform } from '@atscript/moost-validator'
import { UsersController } from './users.controller'
const app = new Moost()
void app.adapter(new MoostHttp()).listen(3000)
app.applyGlobalPipes(validatorPipe()) // validate every Atscript-typed value
app.applyGlobalInterceptors(validationErrorTransform()) // ValidatorError -> 400 response
app.registerControllers(UsersController)
await app.init()With this setup, any handler parameter whose declared type was generated by Atscript (e.g. @Body() dto: CreateUserDto) is validated automatically; failures become structured 400 Bad Request responses.
Where to go next
- Validation Pipe with Atscript — the full guide: DTO authoring, scoping the pipe with
@UseValidatorPipe(), validator options, and the error response shape - API Reference —
validatorPipe,UseValidatorPipe,validationErrorTransform,UseValidationErrorTransform - Atscript documentation — the
.aslanguage, annotations, CLI, and IDE integration