Cottage is the fastest, simple, and intuitive server framework built on Koa.js.
- Fastest Framework on Node - See performance
- 100% Koa.js compatible - You can use all plugins and modules of koa.
- Simple code - Aren't you tired using
res.send
orthis.body
? Why can't we justreturn
the response? - Additional Sugar Features
$ npm install --save cottage
Cottage requires iojs or Node v4.0.0 or higher.
To use it with Node v0.12, you must run node
with the --harmony
flag.
const cottage = require('cottage');
const app = cottage();
app.get('/hello', function*(req, res) {
let hello = yield asyncHello();
return hello; // just return data
});
// 100% fully compatible with koa
app.use(koaMiddleware());
// because cottage is built on the top of Koa.
koa().use(app.callback()).listen(8080);
// simple shorthand without importing koa.
app.listen(8080);
Benchmark have been ran on Intel Xeon E3-1250v3 @ 3.50ghz with Node.js 6.1.0 single instance. Tested from Github API sample using wrk
Framework | Mean Throughput (req/sec) | Stddev |
---|---|---|
cottage@2.1.0 | 15130.12 | 142.45 |
express@4.13.4 | 11455.67 | 201.95 |
koa-router@5.4.0 | 12279.01 | 157.33 |
hapi@13.4.1 | 2402.31 | 53.14 |
As the benchmark result shows, cottage is the fastest framework in Node.js.
Cottage uses Radix Tree for URL routing, which is faster than any other data structures. Also, cottage uses technique called "middleware precomposition", which precomposes middleware only at first time, not the every runtime.
You can write down a code just as you've done on the Express, but using generator-based flow control instead of dirty callback hell.
NOTE THAT It may look exactly like Express handler, but it's very different:
function* (req, res, next) { }
req
iskoa.Request
res
iskoa.Response
next
is aGenerator
that points next middlewaresthis
iskoa.Context
- API Documentation (Currently Working)
- Samples (Currently Working)