https://github.com/kulakowka/feathers-validate-hook
Feathers hook for validate json-schema with is-my-json-valid
https://github.com/kulakowka/feathers-validate-hook
feathers-hook feathersjs json
Last synced: about 1 month ago
JSON representation
Feathers hook for validate json-schema with is-my-json-valid
- Host: GitHub
- URL: https://github.com/kulakowka/feathers-validate-hook
- Owner: kulakowka
- License: mit
- Created: 2016-02-20T17:41:58.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-07-20T03:41:42.000Z (almost 6 years ago)
- Last Synced: 2025-04-15T06:16:19.308Z (about 1 month ago)
- Topics: feathers-hook, feathersjs, json
- Language: HTML
- Homepage: https://code-typing-tutor.com
- Size: 45.9 KB
- Stars: 12
- Watchers: 1
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## feathers-validate-hook
[](https://nodei.co/npm/feathers-validate-hook/)
[](https://www.npmjs.org/package/feathers-validate-hook)
[](https://david-dm.org/kulakowka/feathers-validate-hook)This is experiment. **Work in progress!**
Feathers hook for validate json-schema with [is-my-json-valid](https://www.npmjs.com/package/is-my-json-valid)
```javascript
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](https://github.com/kulakowka/feathers-validate-hook/tree/master/example) 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"
}
]
}
```