a JSONAPI 1.0 plugin for Hapi
Harvester is a Hapi plugin which enables you to define JSONAPI 1.0 resources in an easy, boilerplate-free manner.
// bootstrap a hapi server... and register the plugin
server.register(
[{
register: harvester,
options: {
adapter: adapter({
mongodbUrl: 'mongodb://localhost/test',
oplogConnectionString: 'mongodb://localhost/local'})
}
}], () => {
// define a jsonapi schema
var brands = {
type: 'brands',
attributes: {
// use Joi to set validation constraints
code: Joi.string(),
description: Joi.string()
}
}
const hh = server.plugins['hapi-harvester']
// register the routes
hh.routes.all(brands).forEach((route) => {
server.route(route)
})
server.start()
})
The code for a more complete server can be found in the /example folder.
- CRUD
- Filtering
- Sorting
- Pagination
- Resource Relationships
- Inclusion of Linked Resources
- Sparse fieldsets
- Errors
- Extended filter operators : lt, gt, lte, gte
- Publish change events through SSE