japi

0.0.1 • Public • Published

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

Dependencies (0)

    Dev Dependencies (8)

    Package Sidebar

    Install

    npm i japi

    Weekly Downloads

    0

    Version

    0.0.1

    License

    ISC

    Last publish

    Collaborators

    • confuser