Docs: add "modify the response format" section
This commit is contained in:
parent
a720e30a85
commit
71e6390282
28
README.md
28
README.md
@ -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