UNPKG

2.07 kBMarkdownView Raw
1kick.js
2=======
3
4sinatra style routing framework
5
6```js
7var app = kick();
8
9app.use(function(req, res, next) {
10 req.hello = 'hello world';
11 next();
12})
13
14app.get('/', function(req, res, next) {
15 res.end(req.hello);
16})
17
18app.get('/user/:userid', function(req, res, next) {
19 res.end(req.params.userid + req.hello);
20})
21```
22
23## benchmark
24
25benchmark with [siege.js](https://github.com/guileen/siege.js),
26constant routing has similar RPS with helloworld,
27param routing (30 param routing defined) lose 5% RPS.
28
29node hello world [[code](https://github.com/guileen/kick.js/blob/master/benchmark/node.js)]
30
31 GET:/ without cookie
32 done:100000
33 200 OK: 100000
34 rps: 7495
35 response: 0ms(min) 17ms(max) 1ms(avg)
36
37 GET:/user/30/abcdefg without cookie
38 done:100000
39 200 OK: 100000
40 rps: 7577
41 response: 0ms(min) 17ms(max) 1ms(avg)
42
43kick example [[code](https://github.com/guileen/kick.js/blob/master/benchmark/app.js)]
44
45 GET:/ without cookie
46 done:100000
47 200 OK: 100000
48 rps: 7411
49 response: 0ms(min) 18ms(max) 1ms(avg)
50
51 GET:/user/30/abcdefg without cookie
52 done:100000
53 200 OK: 100000
54 rps: 7079
55 response: 0ms(min) 17ms(max) 1ms(avg)
56
57### app.configure(env, fn)
58### app.use(middleware, ...)
59
60```js
61app.configure('development', function(){
62 app.use(connect.logger('dev'))
63 app.use(connect.static(__dirname + '/public'))
64 app.use(connect.cookieParser('tobo!'))
65 app.use(connect.session());
66});
67```
68
69### app.get(path, middleware, ...)
70
71
72Constant routing, O(1)
73
74```js
75app.get('/about', routes.about);
76```
77
78Param routing, O(N)
79
80```js
81app.get('/user/:userid', function(req, res, next) {
82 res.end(req.params.userid);
83});
84```
85
86Above will match `/user/123` and `req.params.userid` is `123`
87
88Regular expression routing, O(N)
89
90```js
91app.get(/^\/user-(\d+)$/, function(req, res, next) {
92 res.end(req.params[1])
93});
94```
95
96Above will match `/user-123` and `req.params[1]` is `123`
97
98> N = count(params routing) + count(regular expression routing)