• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

therne/cottage: Simple, fast HTTP router on koa.js.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

therne/cottage

开源软件地址:

https://github.com/therne/cottage

开源编程语言:

JavaScript 100.0%

开源软件介绍:

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

Framework Mean Throughput (req/sec) Stddev
[email protected] 15130.12 142.45
[email protected] 11455.67 201.95
[email protected] 12279.01 157.33
[email protected] 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.

Documentations

License: MIT




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap