express-rest-server
v0.0.5
Published
Simple express wrapper that allows quickly adding controller classes and use promises.
Downloads
7
Readme
Express REST server
Usage
- First, create a controller class with a configure method:
class FooController {
configure(router, serveStatic) {
router.get('/', this.getFoos),
router.get('/:id', this.getFoo)
}
getFoos() {
return [ 'foo' ] // you can return the data directly
}
getFoo({ id /* path params */}, { /* query string object */}) {
return Promise.resolve('foo') // or return a promise
}
}
- Then, add controllers and start the server:
const Server = require('./server')
const FooController = require('./foo-controller')
const BarController = require('./bar-controller')
...
let server = new Server(3000)
server.addController('/foo', FooController)
server.addController('/bar', BarController)
...
server.start()