Validate request bodies or query parameters with vinejs.
This package requires that you have vinejs installed.
$ npm i @vinejs/vine @petrichorjs/validator-vinejs
To use this validator you just have to pass the validator
function to either the body or query validator depending on what you want to validate. You also have to pass the vinejs schema to the validator function.
router
.post("/users")
.validate({
body: validator(
vine.object({
id: vine.number().withoutDecimals(),
email: vine.string().email(),
profile: vine.object({
username: vine.string(),
}),
})
),
})
.handle(async ({ request, response }) => {
const data = await request.json();
data; // { id: number, email: string, profile: { username: string }}
});