Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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"
}
]
}
```