https://github.com/paranoiasystem/fastify-autocrud
Plugin for autogenerate CRUD routes as fast as possible
https://github.com/paranoiasystem/fastify-autocrud
Last synced: about 1 year ago
JSON representation
Plugin for autogenerate CRUD routes as fast as possible
- Host: GitHub
- URL: https://github.com/paranoiasystem/fastify-autocrud
- Owner: paranoiasystem
- License: mit
- Created: 2019-08-19T12:30:54.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-01-22T02:09:55.000Z (over 2 years ago)
- Last Synced: 2024-10-12T23:25:46.150Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 101 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-autocrud
[](https://travis-ci.org/paranoiasystem/fastify-autocrud)
[](https://github.com/paranoiasystem/fastify-autocrud/issues)
[](https://coveralls.io/github/paranoiasystem/fastify-autocrud?branch=master)
[](./LICENSE)

[](http://standardjs.com/)
[](https://beerpay.io/paranoiasystem/fastify-autocrud)
Plugin for autogenerate CRUD routes as fast as possible.
## Install
```
npm i fastify-autocrud --save
```
## Usage
```js
fastify.register(require('fastify-autocrud'), {
prefix: '/api/products',
Collection: require('../models/Product')
})
```
**_Product.js_**
```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
```js
const customController = require('customController')
fastify.register(require('fastify-autocrud'), {
prefix: '/api/products',
Collection: require('../models/Product'),
additionalRoute: customController
})
```
**_customController.js_**
```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](./LICENSE).