Skip to content
forked from therne/cottage

Simple, Express-styled API routing framework on koa.js.

Notifications You must be signed in to change notification settings

peter-moon/cottage

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cottage

Join Gitter chat Show build status Coverage report npm Version

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 or this.body? Why can't we just return the response?
  • Additional Sugar Features

Installation

$ 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.

Example

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);

Performance

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.

Why?

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.

Express style, but Koa

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) { }

Documentations

  • API Documentation (Currently Working)
  • Samples (Currently Working)

License: MIT

About

Simple, Express-styled API routing framework on koa.js.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%