1.0.8 • Published 6 years ago

hiep294-route v1.0.8

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

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
1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago