Example #1
0
var protein = require('protein');
var url = require('url');

var mixin = protein()
	.use('request.query', {getter:true}, function() {
		return this._query || (this.query = url.parse(this.url, true).query);
	})
	.use('response.echo', function(data) {
		return this.end(JSON.stringify(data));
	});

var listener = function(request, response) {
	mixin(request, response);
	response.echo(request.query);
};

require('http').createServer(listener).listen(8080);
Example #2
0
var protein = require('protein');

protein()
	.use(require('./middleware/json'))
	.use(require('./middleware/query'))
	.fn('response.echo', function() {
		this.json({time: Date.now(), query: this.request.query});
	})
	.use(function(req, res) {
		res.echo();
	})
	.listen(8888);

console.log('visit http://localhost:8888/?foo=bar');