buunguyen / koa-req-validator

Declarative request validation middleware for Koa
MIT License
19 stars 11 forks source link

Return JSON #9

Open giovannicruz97 opened 5 years ago

giovannicruz97 commented 5 years ago

Hello, there!

Just a doubt: Is it possible to return a JSON instead of a error text message ?

ngphi commented 5 years ago

It's a good idea. Do you have any suggestion how the API would look like?

giovannicruz97 commented 5 years ago

Nice! I think we can start to think on something like this:

const validator = require('koa-req-validator');
const mySchema = require('[json schema location]');
const Router = require('koa-router');
const router = new Router();

router.post('/', validator.default(mySchema, callback(error)));

module.exports = router.routes()