🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@fastify/any-schema

Package Overview
Dependencies
Maintainers
19
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/any-schema

Save multiple schemas and decide which one use to serialize the payload Edit

3.1.0
latest
Source
npm
Version published
Weekly downloads
1
Maintainers
19
Weekly downloads
 
Created
Source

@fastify/any-schema

NPM version CI workflow js-standard-style

Save multiple schemas and decide which one to use to serialize the payload.
Internally uses fast-json-stringify to compile the schemas in extremely fast serialization functions, with all the benefits given by the library, such as preventing the leaking of sensitive data.

Install

npm i @fastify/any-schema

Usage

Register the plugin and pass to it an array of schemas with an id, then use reply.schema(id) to decide which schema to use to serialize your data.

const fastify = require('fastify')()

fastify.register(require('@fastify/any-schema'), {
  schemas: [{
    $id: 'schema1',
    type: 'object',
    properties: {
      hello: { type: 'string' }
    }
  }, {
    $id: 'schema2',
    type: 'object',
    properties: {
      winter: { type: 'string' }
    }
  }]
})

fastify.get('/:schema', (req, reply) => {
  reply
    .schema(req.params.schema)
    .send({ hello: 'world' })
})

fastify.listen({ port: 3000 }, err => {
  if (err) throw err
  console.log(`server listening on ${fastify.server.address().port}`)
})

Acknowledgements

This project is kindly sponsored by:

  • LetzDoIt

License

Licensed under MIT.

Keywords

fastify

FAQs

Package last updated on 05 Dec 2022

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