
Product
Introducing Pull Request Stories to Help Security Teams Track Supply Chain Risks
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
express-decorators-joi
Advanced tools
Middleware for express-decorators that validates request body using Joi
Defines a middleware function for express-decorators that validates request data using Joi.
$ npm install --save express-decorators-joi
import * as web from 'express-decorators';
import validate from 'express-decorators-joi';
@web.controller('/')
class TestController {
@web.get('/test')
@validate(Joi.object().keys({
name: Joi.string().required(),
birthdate: Joi.date().iso()
}))
testAction(request, response) {
// request.data contains the validated (and converted) data
}
}
It validates request.body
, so you'll need body-parser installed and use
d. If the validation fails, the middleware calls next
with a Joi ValidationError
. You should probably trap this error and return an HTTP 400, e.g.:
app.use(function (err, request, response, next) {
if (err.name === 'ValidationError') {
response.status(400).json({error: err.message});
}
});
That's about it.
ISC, do what you want. All bug reports, issues, comments, suggestions and pull requests welcome.
FAQs
Middleware for express-decorators that validates request body using Joi
The npm package express-decorators-joi receives a total of 0 weekly downloads. As such, express-decorators-joi popularity was classified as not popular.
We found that express-decorators-joi 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.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.