cot
cottage
npm i cottage
cot

cottage

Simple, fast HTTP router on koa.js.

by Hyojun Kim

3.1.3 (see all)License:MITTypeScript:Built-In
npm i cottage
Readme
Cottage

Join Gitter chat Show build status Coverage report npm Version

Cottage is the fastest, simple, and intuitive HTTP router framework for Koa.js.

  • Fastest HTTP Router / Framework on Node - See performance
  • Simple code - Aren't you tired using res.send or ctx.body? Why can't we just return the response?
  • Additional Sugar Features

Installation

Cottage requires Node v8.0.0 or higher.

$ npm install cottage

Example

import { Cottage, Response } from 'cottage';
const app = new Cottage();

// just simple return would be enough
app.post('/', async ctx => 'Hello world!');

app.get('/auth', async ctx => {
    // needs fancy response code?
    return new Response(401, { error: 'unauthorized' });
});

// cottage is built on the top of Koa.
app.use(anyKoaMiddleware());
(new Koa).use(app.callback()).listen(...);

// or a simple shorthand without importing Koa.
app.listen(8080, () => console.log('Independent!'));

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

FrameworkMean Throughput (req/sec)Stddev
cottage@2.1.015130.12142.45
express@4.13.411455.67201.95
koa-router@5.4.012279.01157.33
hapi@13.4.12402.3153.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.

Documentations

License: MIT

Downloads/wk

2

GitHub Stars

101

LAST COMMIT

3yrs ago

MAINTAINERS

1

CONTRIBUTORS

3

OPEN ISSUES

4

OPEN PRs

13
VersionTagPublished
3.1.3
latest
3yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate