Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 28 days 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 (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-20T03:41:42.000Z (over 5 years ago)
- Last Synced: 2024-10-04T19:31:03.641Z (about 1 month ago)
- Topics: feathers-hook, feathersjs, json
- Language: HTML
- Homepage: https://code-typing-tutor.com
- Size: 45.9 KB
- Stars: 12
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## feathers-validate-hook
[![npm package](https://nodei.co/npm/feathers-validate-hook.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/feathers-validate-hook/)
[![NPM version](http://img.shields.io/npm/v/feathers-validate-hook.svg)](https://www.npmjs.org/package/feathers-validate-hook)
[![Dependency Status](https://david-dm.org/kulakowka/feathers-validate-hook.svg)](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"
}
]
}
```