qweb
v0.2.7
Published
A very simple http route framework
Downloads
5
Readme
qweb
A very simple web framework
install
npm install qweb --save
init
var qweb = require('qweb');
var server = qweb();
basic dict route
qweb({path: handler})
var server = qweb({
'/foo': function(req, res) {
res.end('foo');
}
});
route with method
Support ALL HTTP Verb like GET, POST, PUT, ...
var server = qweb();
server.get('/foo', function(req, res) {
});
server.post('/foo', function(req, res) {
});
route with named params
qweb().get('/foo/:id', function(req, res) {
res.end(req.params.id);
});
route or wild-card.
qweb().get('/foo/*', function(req, res) {
res.end(req.params[0]);
});
req.query
qweb().get('/foo', function(req, res) {
console.log(req.query);
});
req.res
res.req
server.before(function(req, res))
server.after(function(req, res))
Event: domainError function(error, req, res)
extend request and response.
You can extend request and response method by below method.
qweb.res.json = function(obj) {
this.writeHead({'Content-Type': 'application/json'});
this.end(JSON.stringify(obj));
}