fastify-fastest-validator
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Fastify Fastest Validator

This plugin provides a simple way to validate incoming requests using the fastest-validator library.

Installation

pnpm install fastify-fastest-validator

Usage

import fastify from 'fastify';
import fastifyFastestValidator from 'fastify-fastest-validator';

const app = fastify();

app.register(fastifyFastestValidator, {
  validatorOptions: {
    // fastest-validator options
  },
});

app.get('/hello', {
  validationConfig: {
    querySchema: {
      name: { type: 'string' },
    },
  },
}, async (request, reply) => {
  return `Hello, ${request.query.name}!`;
});

The sample code above demonstrates how to use the fastify-fastest-validator plugin to validate incoming requests. The validationConfig object is used to specify the schema for validating the request parameters. If any validation errors occur, a 400 Bad Request response is returned with an array of error messages.

Options

The plugin accepts the following options:

  • validatorOptions: Options to pass to the fastest-validator constructor.

Readme

Keywords

none

Package Sidebar

Install

npm i fastify-fastest-validator

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

7.12 kB

Total Files

7

Last publish

Collaborators

  • anderson.joseph