Socket
Socket
Sign inDemoInstall

express-decorators-joi

Package Overview
Dependencies
31
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    express-decorators-joi

Middleware for express-decorators that validates request body using Joi


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Install size
7.72 MB
Created
Weekly downloads
 

Readme

Source

express-decorators-joi

Defines a middleware function for express-decorators that validates request data using Joi.

Installation

$ npm install --save express-decorators-joi

Usage

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 used. 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.

Licence etc

ISC, do what you want. All bug reports, issues, comments, suggestions and pull requests welcome.

Keywords

FAQs

Last updated on 12 Feb 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc