Socket
Book a DemoInstallSign in
Socket

express-decorators-joi

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-decorators-joi

Middleware for express-decorators that validates request body using Joi

0.1.0
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
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

express-decorators

FAQs

Package last updated on 12 Feb 2016

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.