0.0.4 • Published 9 years ago

restware v0.0.4

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

restware

Lightweight REST API framework for Node.js, built on top of connect.

Status

Alpha version

Features

  • Lightweight and fast
  • Strict REST
  • Versioned routing
  • Resource expansion

Why not Restify?

Restify is great, but it comes with semver versioning which is not the best choice when it comes to the API, DTrace as a dependency is also not a very good idea and Restify is actually very slow.

Restware tries to implement streight-forward versioning and routing that would make the deployment of new versions and hotfixes easier.

Instead of creating the whole new framework, Restware is actually just a set of middlewares for connect, that means you can choose what you want to use and you can also use other connect middlewares.

Connect is fast and Restware's middleware is also very efficient - it does only what the REST API needs. This makes Restware much faster then Restify (benchmark is comming soon).

Install

$ npm install restware

Usage

var http = require('http'),
  connect = require('connect'),
  restware = require('restware');

var server = connect();

http.createServer(server);

server.use(restware.requestId());
server.use(restware.gzip());
server.use(restware.cors());
server.use(restware.queryParser());
server.use(restware.bodyParser());
server.use(restware.acceptParser());
server.use(restware.authParser());
server.use(restware.rangeParser());
server.use(restware.methodOverride());
server.use(restware.validator());
server.use(restware.requestHandler());
server.use(restware.errorHandler());
server.use(restware.formatter());

// register your controllers
restware.dispatcher.register(1, {
  users: {
    // mapped to GET /users
    getCollection: function (req, reply) {
      reply([...]);
    },
    // mapped to GET /users/:id
    getModel: function(req, reply){
      reply({ id: ... })
    },
    // mapped to PUT /users
    putCollection: function(req, reply){
      
    }
  }
});

server.listen(3000, function () {
  console.log('Listening on port 3000');
});

Examples

For more information about usage see /examples directory where you'll find more about versioning, resource expansion and streaming.

Test

Requires nodeunit

$ npm test

License

MIT

0.0.4

9 years ago

0.0.2

9 years ago