REST-Ana
Super fast and minimalist web framework for building REST micro-services.
Usage
npm i restana --save
const service = require('restana')({});
const PetsModel = {
};
service.get('/pets/:id', (req, res) => {
res.send(PetsModel.findOne(req.params.id));
});
service.get('/pets', (req, res) => {
res.send(PetsModel.find());
});
service.delete('/pets/:id', (req, res) => {
res.send(PetsModel.destroy(req.params.id));
});
service.post('/pets/:name/:age', (req, res) => {
res.send(PetsModel.create(req.params));
});
service.patch('/pets/:id', function (req, res) {
res.send(this.update(req.params.id, JSON.stringify(req.body)));
}, PetsModel);
service.get('/version', function (req, res) {
res.body = {
version: '1.0.0'
}
res.send();
});
service.start(3000).then((server) => {});
service.close().then(()=> {});
Supported methods:
const methods = ['get', 'delete', 'put', 'patch', 'post', 'put', 'head', 'options'];
Middleware usage:
const service = require('restana')({});
service.use((req, res, next) => {
let now = new Date().getTime();
res.on('response', data => {
data.res.setHeader('X-Response-Time', new Date().getTime() - now);
});
return next();
});
service.get('/v1/welcome', (req, res) => {
res.send('Hello World!');
});
service.start();
Third party middlewares support:
Almost all middlewares using the function (req, res, next) signature format should work. With the consideration that they don't use any custom framework feature.
Examples :
Performance comparison
Performance comparison for a basic Hello World! response in cluster mode with 4 processes:
ab -n 10000 -c 1000 http://localhost:3000/v1/welcome
Results:
- restana: ~1300ms
- koa: ~1500ms
- hapi: ~4200ms
- express: ~1800ms
- restify: ~2000ms