koa-req-validator icon indicating copy to clipboard operation
koa-req-validator copied to clipboard

Return JSON

Open giovannicruz97 opened this issue 5 years ago • 2 comments

Hello, there!

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

giovannicruz97 avatar May 03 '19 17:05 giovannicruz97

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

ngphi avatar May 03 '19 23:05 ngphi

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()

giovannicruz97 avatar May 06 '19 11:05 giovannicruz97