Socket
Book a DemoInstallSign in
Socket

fastify-autocrud

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-autocrud

Plugin for autogenerate CRUD route as fast as possible.

0.0.4
latest
Source
npmnpm
Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

fastify-autocrud

build status issues Coverage Status license version js-standard-style Beerpay

Plugin for autogenerate CRUD routes as fast as possible.

Install

npm i fastify-autocrud --save

Usage

fastify.register(require('fastify-autocrud'), {
    prefix: '/api/products',
    Collection: require('../models/Product')
})

Product.js

const mongoose = require('mongoose')

const Product = new mongoose.Schema({
  name: String,
  description: String,
  image: String,
  cost: Number,
  price: Number,
  qty: Number
}, {
  timestamps: true
})

module.exports = mongoose.model('Product', Product)

If you want add custom routes

const customController = require('customController')

fastify.register(require('fastify-autocrud'), {
    prefix: '/api/products',
    Collection: require('../models/Product'),
    additionalRoute: customController
})

customController.js

const boom = require('boom')

const customRoute = {
    method: 'GET',
    url: '/custom',
    handler: async function (req, reply) {
        try {
            reply.type('application/json').code(200).send({ "customroute": "ok" })
        } catch (err) {
            throw boom.boomify(err)
        }
    }
}

module.exports = [customRoute]

License

Licensed under MIT.

Keywords

fastify

FAQs

Package last updated on 20 Aug 2019

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.