1.0.4 • Published 4 years ago
request-validator-node v1.0.4
Request Validator Node
Validator Service for Requests coming on Node Server
Installation
Installing with npm
npm i request-validator-node
Installing with yarn
yarn add request-validator-node
Getting Started
1: Create json file for your request schema.
{
"type": "object",
"additionalProperties": false,
"required": [
"email",
"password"
],
"properties": {
"email": {
"type": "string",
"format": "email"
},
"password": {
"type": "string"
}
}
}
2: Create Validator class specifying the schema path.
export class DemoValidator extends ValidatorAbstract {
protected getValidatorInstance(): ValidatorService {
return ValidatorService.init({schemaFolder: ""}); // Optional: Enter folder where request schema files are placed or pass {}
}
protected getSchemaName(): string {
return "demo.schema.json";
}
}
3: Call Validate function on Validator instance.
await new DemoValidator().validate(req.body);