japi
v0.0.1
Published
Send Joi errors in jsonapi format
Downloads
2
Readme
japi
Provides a Hapi failAction
to return Joi validation errors in jsonapi format
Installation
npm install japi --save
Usage
var Hapi = require('hapi')
, Joi = require('joi')
, failAction = require('japi').failAction
, server = new Hapi.Server().connection(
{ routes:
{ validate:
{ options:
{ abortEarly: false }
}
}
})
server.route(
{ method: 'POST'
, path: '/'
, handler: function (request, reply) { reply() }
, config:
{ validate:
{ payload: { name: Joi.string().required() }
, failAction: failAction
}
}
})
/*
Example response:
{ errors:
[ { source: { pointer: 'name' }
, detail: '"name" is required'
, title: 'required'
}
]
}
*/