https://github.com/confuser/japi
Send Joi errors in jsonapi format
https://github.com/confuser/japi
Last synced: 9 months ago
JSON representation
Send Joi errors in jsonapi format
- Host: GitHub
- URL: https://github.com/confuser/japi
- Owner: confuser
- License: isc
- Created: 2016-07-17T10:30:14.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-17T10:35:15.000Z (almost 10 years ago)
- Last Synced: 2025-08-15T18:23:24.345Z (10 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# japi
[](https://travis-ci.org/confuser/japi)
[](https://coveralls.io/r/confuser/japi?branch=master)
Provides a Hapi `failAction` to return Joi validation errors in jsonapi format
## Installation
```
npm install japi --save
```
## Usage
```js
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'
}
]
}
*/
```