hiep294-route
v1.0.8
Published
Requirement modules: express, mongoose
Downloads
2
Readme
Use this for ExpressJS API
Requirement modules: express, mongoose
Example
Exampled a model Website, based on mongoose
module
const mongoose = require('mongoose');
const Schema = mongoose.Schema
const websiteSchema = new Schema({
link: {
type: String,
required: [true, 'Link field is empty, please fill it up!']
},
description: {
type: String,
required: [true, 'Description field is empty, please fill it up!']
},
date: {
type: Date,
default: Date.now
}
})
module.exports = mongoose.model('Website', websiteSchema);
websiteItemRoute
const Route = require('hiep294-route')
itemRoute = Route({
Model: require('../../models/Website'),
actions: ['index', 'create', 'update', 'destroy']
}) /* can optional pick a number of actions above */
module.exports = itemRoute
Routes:
- / : method GET to index
- / : method POST to create
- /:id : method PUT to update
- /:id : method DELETE to delete(destroy)
please check down the response in client side. the response may include status
, errors
, info
in need
Use route in server
app.use(url, itemRoute)
Change log
- 1.0.7: Modify errors in response
- 1.0.6: Modify errors in response
- 1.0.5: Update Readme
- 1.0.4: Name convention