1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-02 22:17:10 +08:00
Drasko DRASKOVIC 59da29ff2b Use restify and mongojs. Change structure.
This commit introducess massive change:
- Replace Express by Restify for simplicity and lean approach
- Replace Mongoose by MongoJS for DB schema-less paradigm
- Introduce `controllers` dir, and isolate all routes in `routes.js`

Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
2015-12-02 00:17:10 +01:00

45 lines
1.5 KiB
JavaScript

var restify = require('restify');
var config = require('../config/config');
var devicesController = require('./controllers/devices');
var statusController = require('./controllers/status');
var rateLimit = restify.throttle({
burst: config.limiter.defaultBurstRate,
rate: config.limiter.defaultRatePerSec,
ip: true
});
function routes(api) {
/**
* /STATUS
*/
api.get('/status', rateLimit, statusController.getStatus);
/**
* /DEVICES
*/
/** Create a device (accessed at POST http://localhost:8080/devices) */
api.post('/devices', rateLimit, devicesController.createDevice);
/** Get all the devices (accessed at GET http://localhost:8080/devices) */
api.get('/devices', rateLimit, devicesController.getAllDevices);
/**
* /devices/:device_id
* N.B. Colon (`:`) is needed because of Express `req.params`: http://expressjs.com/api.html#req.params
*/
/** Get the device with given id (accessed at GET http://localhost:8080/devices/:device_id) */
api.get('/devices/:device_id', rateLimit, devicesController.getDevice)
/** Update the device with given id (accessed at PUT http://localhost:8080/devices/:device_id) */
api.put('/devices/:device_id', rateLimit, devicesController.updateDevice)
/** Delete the device with given id (accessed at DELETE http://localhost:8080/devices/:device_id) */
api.del('/devices/:device_id', rateLimit, devicesController.deleteDevice);
}
module.exports = routes;