1.0.0 • Published 6 years ago
koa-fluent-validation v1.0.0
koa-fluent-validation
Fluent, functional, and extendable validation for Koa 2 body, params, and query. Built on validator for base validations and filters.
Installation
$ npm i koa-fluent-validation
Requirements
- NodeJS >= 7.6
- For validating parameters, koa-router's implementation is used with
ctx.params
.
Usage
Simple App Example
const Koa = require('koa');
const bodyparser = require('koa-bodyparser');
const { validation, v, f } = require('koa-fluent-validation');
const app = new Koa();
app.use(bodyparser());
app.use(validation());
app.use(async (ctx, next) => {
try {
await next();
} catch (e) {
if (e.status === 422) {
ctx.body = ctx.validationErrors;
return;
}
// ... some other handling here etc
}
});
// simple post route
app.use(async (ctx, next) => {
if (ctx.method !== 'POST') {
ctx.throw(404);
return;
}
ctx.validateBody(
{
firstName: v()
.required()
.string(),
lastName: v()
.required()
.string(),
},
{
firstName: f().trim(),
lastName: f().trim(),
},
);
// your code here
});
app.listen(8080);
Documentation
For documentation see the wiki!
TODO
- [] Filter Tests
1.0.0
6 years ago
0.14.0
6 years ago
0.12.3
6 years ago
0.12.2
6 years ago
0.12.1
6 years ago
0.12.0
6 years ago
0.11.0
6 years ago
0.10.1
6 years ago
0.10.0
7 years ago
0.9.0
7 years ago
0.8.1
7 years ago
0.8.0
7 years ago
0.7.1
7 years ago
0.7.0
7 years ago
0.6.2
8 years ago
0.6.1
8 years ago
0.6.0
8 years ago
0.5.3
8 years ago
0.5.2
8 years ago
0.5.1
8 years ago
0.5.0
8 years ago
0.4.1
8 years ago
0.4.0
8 years ago
0.3.0
8 years ago
0.2.0
8 years ago
0.1.0
8 years ago