0.0.1 • Published 8 years ago

japi v0.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
8 years ago

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