# joi-validate-middleware

> Validate middleware generator using Joi

Latest version **1.0.4** (published 2020-01-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install joi-validate-middleware
pnpm add joi-validate-middleware
yarn add joi-validate-middleware
bun add joi-validate-middleware
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-01-14 |
| First published | 2020-01-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Park Si-Yual |
| Maintainers | araxsiyual |
| Keywords | koa, middleware, joi, validate |

## Links

- npm: https://www.npmjs.com/package/joi-validate-middleware
- Homepage: https://github.com/kdPark0723/joi-validate-middleware
- Issues: https://github.com/kdPark0723/joi-validate-middleware/issues
- npm.io page: https://npm.io/package/joi-validate-middleware

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 1.0.4 (latest) — 2020-01-14
- 1.0.3 — 2020-01-14
- 1.0.2 — 2020-01-14
- 1.0.1 — 2020-01-14
- 1.0.0 — 2020-01-14
- 0.0.0 — 2020-01-14

## README

# Joi Validate Middleware

**Validate middleware generator using *[Joi](https://www.npmjs.com/package/@hapi/joi)(^17.0.2)***

​    

## Install

```shell
$ npm i joi-validate-middleware
```

​    

## Usage

```js
const Joi = require('@hapi/joi');
const joiValidateMiddleware = require('joi-validate-middleware');

const schema = {
  params: Joi.object({
    id: Joi.number().required(),
  }).required(),
  body: Joi.object({
    content: Joi.string().required(),
  }).required()
};

/* or
const schema = {
  params: {
    id: Joi.number().required(),
  },
  body: {
    content: Joi.string().required(),
  }
};
*/

const validate = joiValidateMiddleware.create(schema);

const successRequest = {
  params: {
    id: 1,
  },
  body: {
    content: 'test',
  }
};

validate(successRequest);
console.log('success');

const errorRequest = {
  params: {
    id: 'other',
  },
};

try {
  validate(errorRequest);
  console.log('fail');
} catch (e) {
  console.log('success');
}
```

---
_Source: https://npm.io/package/joi-validate-middleware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
