a tiny middleware library for q promises - EXPERIMENTAL
everyware is a tiny experimental Q promise middleware library. It is intended mainly for middleware library authors, not application developers — it could be used to implement a library like jaque, but does not replace such a library.
In everyware, just as in Q-JSGI, an application is a function of one
env) which returns a response or a promise of a
response. A middleware is a function of one argument (the "next"
application) which returns an application.
A silly example:
return status: 404 body: "not found";return status: 200 body: "foo";returnreturnif envurl == urlreturn appenv;elsereturn nextenv;;;// w takes an app and variadic middleware, and returns an app with the// middleware appliedvar w = require'everyware';var app = wnotFound route"/foo" foo;
everyware does not assume that the middleware stack is used for handling HTTP requests. It is meant to be reused in different contexts. The middleware pattern is useful for more than HTTP — everyware provides the basics so you can easily start using this pattern in your domain.
everyware is currently used in backbone-live to build Backbone.sync implementations using functional Q middleware.
everyware strives for simplicity over convenience. JSGI style for middleware may seem less convenient than connect style, but it is simpler.
everyware makes an additional simplifying assumption that middlewares
are functions of exactly one argument, requiring another closure to
pass other arguments to a middleware (
app in the