@yeongjet/middleware-joi
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Marble.js logo

@marblejs/middleware-joi

A joi validation middleware for Marble.js.

Installation

$ npm i @marblejs/middleware-joi

Requires @marblejs/core to be installed.

Documentation

For the latest updates, documentation, change log, and release information visit docs.marblejs.com and follow @marble_js on Twitter.

Usage

Example of using this middleware on a GET route to validate params.

import { validator$, Joi } from '@marblejs/middleware-joi';

const foo$ = r.pipe(
  r.matchPath('/foo/:id'),
  r.matchType('GET'),
  r.useEffect(req$ => req$.pipe(
    use(validator$({
      params: Joi.object({
        id: Joi.number().min(1).max(10),
      })
    }));
    // ...
  )));

Example to validate all incoming requests.

import { validator$, Joi } from '@marblejs/middleware-joi';

const middlewares = [
  logger$,
  validator$({
    headers: Joi.object({
      sign: Joi.string(),
      accept: Joi.string().default('application/json'),
    }),
    params: Joi.object({
      apiKey: Joi.string().token().required(),
    })
  })
];

const effects = [
  endpoint1$,
  endpoint2$,
  ...
];

const app = httpListener({ middlewares, effects });

License: MIT

Package Sidebar

Install

npm i @yeongjet/middleware-joi

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

7.66 kB

Total Files

11

Last publish

Collaborators

  • yeongjet