Docs: add "modify the response format" section
This commit is contained in:
parent
a720e30a85
commit
71e6390282
30
README.md
30
README.md
@ -9,7 +9,7 @@ This plugin depends on [`hapi-sequelize`](https://github.com/danecando/hapi-sequ
|
|||||||
npm install -S hapi-sequelize-crud
|
npm install -S hapi-sequelize-crud
|
||||||
```
|
```
|
||||||
|
|
||||||
##Configure
|
## Configure
|
||||||
|
|
||||||
Please note that you should register `hapi-sequelize-crud` after defining your
|
Please note that you should register `hapi-sequelize-crud` after defining your
|
||||||
associations.
|
associations.
|
||||||
@ -52,6 +52,13 @@ await register({
|
|||||||
// `config` if provided, overrides the default config
|
// `config` if provided, overrides the default config
|
||||||
{model: 'bat', methods: ['list'], config: { ... }},
|
{model: 'bat', methods: ['list'], config: { ... }},
|
||||||
{model: 'bat', methods: ['create']}
|
{model: 'bat', methods: ['create']}
|
||||||
|
// change the response data
|
||||||
|
{model: 'fly', config: {
|
||||||
|
response: {
|
||||||
|
schema: {id: joi.string()},
|
||||||
|
modify: true
|
||||||
|
}
|
||||||
|
}}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -110,6 +117,27 @@ If you want to get multiple related models, just pass multiple `include` paramet
|
|||||||
Team.findAll({include: [City, Uniform]})
|
Team.findAll({include: [City, Uniform]})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Modify the response format
|
||||||
|
By default, `hapi-sequelize-crud` routes will respond with the full model. You can modify this using the built-in [hapi settings](http://hapijs.com/tutorials/validation#output).
|
||||||
|
|
||||||
|
```js
|
||||||
|
await register({
|
||||||
|
register: require('hapi-sequelize-crud'),
|
||||||
|
options: {
|
||||||
|
…
|
||||||
|
{model: 'fly', config: {
|
||||||
|
response: {
|
||||||
|
// setting this schema will restrict the response to only the id
|
||||||
|
schema: { id: joi.string() },
|
||||||
|
// This tells Hapi to restrict the response to the keys specified in `schema`
|
||||||
|
modify: true
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
## Full list of methods
|
## Full list of methods
|
||||||
|
|
||||||
Let's say you have a `many-to-many` association like this:
|
Let's say you have a `many-to-many` association like this:
|
||||||
|
Loading…
Reference in New Issue
Block a user