Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

restana

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restana

Super fast and minimalist web framework for building REST micro-services.

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.8K
decreased by-22.37%
Maintainers
1
Weekly downloads
 
Created
Source

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); // attaching this context

service.get('/version', function (req, res) {
    res.body = { // optionally you can send the response data in the body property
        version: '1.0.0'
    }
    res.send(); // 200 is the defacult response code
});

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')({});

// custom middleware to attach the X-Response-Time header to the response
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();
});

// the /v1/welcome route handler
service.get('/v1/welcome', (req, res) => {
    res.send('Hello World!');
});

// start the server
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 :

  • raw-body: https://www.npmjs.com/package/raw-body. See demo: raw-body.js
  • express-jwt: https://www.npmjs.com/package/express-jwt. See demo: express-jwt.js
  • body-parser: https://www.npmjs.com/package/body-parser. See demo: body-parser.js

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

Keywords

FAQs

Package last updated on 29 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc