https://github.com/brian9206/koa-ajv-validator
Simple Koa ajv JSON schema validator middleware
https://github.com/brian9206/koa-ajv-validator
koa middleware
Last synced: 2 months ago
JSON representation
Simple Koa ajv JSON schema validator middleware
- Host: GitHub
- URL: https://github.com/brian9206/koa-ajv-validator
- Owner: brian9206
- License: mit
- Created: 2018-05-16T13:35:07.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-06T12:14:48.000Z (almost 7 years ago)
- Last Synced: 2024-04-24T17:08:16.488Z (about 1 year ago)
- Topics: koa, middleware
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-ajv-validator
Koa middleware for quick ajv json body validation implementation## Usage
```js
const Koa = require('koa');
const body = require('koa-body');
const body_validator = require('koa-ajv-validator');const app = new Koa();
app
.use(body())
.use(body_validator({
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
},
"required": ["firstName", "lastName"]
}))
.use(async ctx => {
ctx.body = 'Your JSON is good'
})
.listen(8080);app.on('error', (err, ctx) => {
console.log(err);
});
```