japi
Send Joi errors in jsonapi format
Last updated 4 years ago by confuser .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install japi 
SYNC missed versions from official npm registry.

japi

Build Status Coverage Status

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'
    }
  ]
}
*/

Current Tags

  • 0.0.1                                ...           latest (4 years ago)

1 Versions

  • 0.0.1                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (8)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |