regio
v0.2.0
Published
Minimalist web framework with express-like aspirations, targeted at embedded devices.
Downloads
10
Readme
regio
Minimalist web framework with express-like aspirations, targeted at embedded devices like Tessel and Espruino. Therefore, instead being a mighty express it is just a regional train...
Motivation
So why another framework?
This framework started as a test suite while investigating how to get express running on Tessel.
Because there were simply too many moving parts in slimming down express, I've decided to start with a clean slate and incorporate express middlewares one at a time.
In the process I found out that there is quite a lot of stuff to handle pre 4.x API, disambiguation of function parameters and also too many convenience methods for such a constrained environment as on the devices I was targeting.
So, I've decided to keep the test framework around and use express middleware and components where it does feel appropriate, especially as Espruino is also a target environment.
Installation
npm install regio
Usage
var regio = require('regio');
var app = regio();
app.get('/', function(req, res) {
res.status(200).send({
message: 'Hello World'
}).end();
});
app.use(function (req, res, next) {
req.message = 'added by middleware';
next();
});
var subapp = regio.router();
subapp.get('/', function(req, res) {
res.status(200).send({
message: 'I\'m a mounted application'
}).end();
});
subapp.on('active', function() {
// server is up, I can receive requests
});
app.use('/mounted', subapp);
var server = app.listen(8080, function() {
console.log('app started on port', server.address().port);
});
Express compatibility
Application
Request
- req.params
Response
- res.status
- res.set
- res.get
- res.send
Router
- router()
- router.use
- router.VERB
- router.all
- events
- mounted is triggered when router is mounted
- active is triggered when server is listening
Middleware
- can be used application and router level, using
.use
or.verb
.
Tests
Currently the test run in node but the plan is to move them to colony.
npm test