Feathers hook for validate json-schema with is-my-json-valid
HTML JavaScript
Switch branches/tags
Nothing to show
Latest commit 4c31d35 Oct 9, 2016 @kulakowka committed on GitHub Update index.js
Permalink
Failed to load latest commit information.
example Update index.js Oct 9, 2016
lib/validate remove schema predefined object Oct 9, 2016
.gitignore init Feb 28, 2016
LICENSE init Feb 28, 2016
README.md Update README.md Oct 9, 2016
package.json init Feb 28, 2016

README.md

feathers-validate-hook

npm package

NPM version Dependency Status

This is experiment. Work in progress!

Feathers hook for validate json-schema with is-my-json-valid

const validateHook = require('feathers-validate-hook')

// Define schema 
const schema = {
  required: true,
  type: 'object',
  properties: {
    // Required attribute 'text' with type 'string'
    text: {
      required: true,
      type: 'string'
    }
  }
}

app.service('/messages').before({
  create: [ 
    validateHook(schema)
  ]
})

Example

Look example folder for more information.

Test request:

curl -H "Accept: application/json" -X POST http://localhost:3030/messages

Server response example:

{
  "name": "BadRequest",
  "message": "Validation failed",
  "code": 400,
  "className": "bad-request",
  "data": {},
  "errors": [
    {
      "field": "data.text",
      "message": "is required",
      "type": "string"
    }
  ]
}