@petrichorjs/validator-vinejs
v1.0.1
Published
Validate request bodies or query parameters with [vinejs](https://vinejs.dev/docs/introduction).
Downloads
4
Readme
@petrichorjs/validator-vinejs
Validate request bodies or query parameters with vinejs.
Installation
This package requires that you have vinejs installed.
$ npm i @vinejs/vine @petrichorjs/validator-vinejs
Docs
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 }}
});