Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
hapi-forest
Advanced tools
Provides REST handlers for mongoose models. Can also generate ready to use routes, for fast bootstrapping.
You can already play around with hapi-forest, but this is missing:
PUT
routenpm i --save hapi-forest # or yarn add hapi-forest if you prefer
// register hapi-forest
server.register({
register: require('hapi-forest'),
options: {
// add your models here for auto route generation
bootstrap: [ require('./models/user-model') ]
}
});
Take a look at the example
directory for a full example.
bootstrap: [ MongooseModel, MongooseModel, … ]
Will generate ready to use CRUD routes. hapi-forest will attempt to generate a basic joi schema based on the model.
You can use the forest
handler and define your own routes, instead of auto-generating
them. This is useful if you need more control over your endpoints or want custom validation.
The forest handler behaves differently based on your route definition.
GET
, POST
, PATCH
& PUT
are supported.
You can also overwrite the behaviour by setting the type
option.
The model
option is always required.
getOne
Returns all documents from the specified model
.
select
.idKey
to be used for lookup instead of
_id
. The path key should be the same name.server.route({
method: 'GET',
path: '/users/{name}', // {name} should be the same as the idKey
handler: {
forest: {
model: User,
idKey: 'name', // custom mongoose field to use as the id
}
}
});
getAll
Returns all documents from the specified model
. The result will be streamed.
select
.filterByQuery
option allows basic filtering of the results by sending a
query with the request. (?group=nodejs&role=developer
)server.route({
method: 'GET',
path: '/users',
handler: {
forest: {
model: User,
select: 'firstName group lastName birthday',
}
}
});
post
Creates a new document.
server.route({
method: 'POST',
path: '/users',
handler: {
forest: {
model: User
}
}
});
put
Updates an existing document or creates a new document if it does not exist.
For now an update will not overwrite and existing document but only update it,
like patch
does.
allowUpsert: false
. PUT will behave like PATCH in that case.idKey
.
In that case the _id
field will be autogenerated and not set by the user.server.route({
method: 'PUT',
path: '/users/{name}',
handler: {
forest: {
model: User,
allowUpsert: true,
idKey: 'name',
}
}
});
delete
Deletes a document.
idKey
that will be used for lookup instead of _id
.server.route({
method: 'DELETE',
path: '/users/{name}',
handler: {
forest: {
model: User,
idKey: 'name',
}
}
});
FAQs
A hapi plugin to generate routes based on mongoose models
The npm package hapi-forest receives a total of 16 weekly downloads. As such, hapi-forest popularity was classified as not popular.
We found that hapi-forest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.