You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Tweaked Node.js HTTP server for high throughput.
10
+
-High-performance and customizable request routers.
11
11
12
-

13
-
> [You can read more about this numbers here.](https://github.com/the-benchmarker/web-frameworks/blob/e00f4b9fc3db7105d8c918c36691560be069697c/README.md)
12
+

13
+
> Check it yourself: https://web-frameworks-benchmark.netlify.app/result?f=feathersjs,0http,koa,fastify,nestjs-express,express,sails,nestjs-fastify,restana
`0http` allows you to define the router implementation you prefer as soon as it support the following interface:
37
-
```js
38
-
router.lookup= (req, res) // -> should trigger router search and handlers execution
39
-
```
40
-
41
-
### 0http - sequential (default router)
42
-
This a `0http` extended implementation of the [trouter](https://www.npmjs.com/package/trouter) router. Includes support for middlewares, nested routers and shortcuts for routes registration.
43
-
As this is an iterative regular expression matching router, it tends to be slower than `find-my-way` when the number of registered routes increases; to mitigate this issue, we use
44
-
an internal(optional) LRU cache to store the matching results of the previous requests, resulting on a super-fast matching process.
-**defaultRoute**: Route handler when there is no router matching. Default value:
73
-
```js
74
-
(req, res) => {
75
-
res.statusCode=404
76
-
res.end()
77
-
}
78
-
```
79
-
-**cacheSize**: Router matching LRU cache size. A given value <= 0 will disable the cache. Default value: `1000`
80
-
-**errorHandler**: Global error handler function. Default value:
81
-
82
-
```js
83
-
(err, req, res) => {
84
-
res.statusCode=500
85
-
res.end(err.message)
86
-
}
87
-
```
88
-
89
-
***prioRequestsProcessing**: `true` to use SetImmediate to prioritize router lookup, `false` to disable. By default `true`, if used with native Node.js `http` and `https` servers. Set to `false`, if using Node.js Native Addon server, such as uWebSockets.js, as this will cause a huge performance penalty
Super-fast raw HTTP router with no goodies. Internally uses a [Radix Tree](https://en.wikipedia.org/wiki/Radix_tree)
138
-
router that will bring better performance over iterative regular expressions matching.
139
-
```js
140
-
constcero=require('../index')
141
-
const { router, server } =cero({
142
-
router:require('find-my-way')()
143
-
})
144
-
145
-
router.on('GET', '/hi', (req, res) => {
146
-
res.end('Hello World!')
147
-
})
148
-
149
-
server.listen(3000)
150
-
```
151
-
152
-
153
-
## Servers
154
-
`0http` is just a wrapper for the servers and routers implementations you provide.
155
-
```js
156
-
constcero=require('0http')
157
-
158
-
const { router, server } =cero({
159
-
server: yourCustomServerInstance
160
-
})
161
-
```
162
-
163
-
### Node.js http.Server
164
-
If no server is provided by configuration, the standard Node.js [http.Server](https://nodejs.org/api/http.html#http_class_http_server) implementation is used.
165
-
Because this server offers the best balance between Node.js ecosystem compatibility and performance, we highly recommend it for most use cases.
- Tweaked Node.js HTTP server for high throughput.
10
+
- High-performance and customizable request routers.
11
+
12
+

13
+
> Check it yourself: https://web-frameworks-benchmark.netlify.app/result?f=feathersjs,0http,koa,fastify,nestjs-express,express,sails,nestjs-fastify,restana
14
+
15
+
## Usage
16
+
```js
17
+
constcero=require('0http')
18
+
const { router, server } =cero()
19
+
20
+
router.get('/hello', (req, res) => {
21
+
res.end('Hello World!')
22
+
})
23
+
24
+
router.post('/do', (req, res) => {
25
+
// ...
26
+
res.statusCode=201
27
+
res.end()
28
+
})
29
+
30
+
//...
31
+
32
+
server.listen(3000)
33
+
```
34
+
35
+
# Routers
36
+
`0http` allows you to define the router implementation you prefer as soon as it support the following interface:
37
+
```js
38
+
router.lookup= (req, res) // -> should trigger router search and handlers execution
39
+
```
40
+
41
+
## 0http - sequential (default router)
42
+
This a `0http` extended implementation of the [trouter](https://www.npmjs.com/package/trouter) router. Includes support for middlewares, nested routers and shortcuts for routes registration.
43
+
As this is an iterative regular expression matching router, it tends to be slower than `find-my-way` when the number of registered routes increases; to mitigate this issue, we use
44
+
an internal(optional) LRU cache to store the matching results of the previous requests, resulting on a super-fast matching process.
-**defaultRoute**: Route handler when there is no router matching. Default value:
73
+
```js
74
+
(req, res) => {
75
+
res.statusCode=404
76
+
res.end()
77
+
}
78
+
```
79
+
-**cacheSize**: Router matching LRU cache size. A given value <= 0 will disable the cache. Default value: `1000`
80
+
-**errorHandler**: Global error handler function. Default value:
81
+
82
+
```js
83
+
(err, req, res) => {
84
+
res.statusCode=500
85
+
res.end(err.message)
86
+
}
87
+
```
88
+
89
+
***prioRequestsProcessing**: `true` to use SetImmediate to prioritize router lookup, `false` to disable. By default `true`, if used with native Node.js `http` and `https` servers. Set to `false`, if using Node.js Native Addon server, such as uWebSockets.js, as this will cause a huge performance penalty
Super-fast raw HTTP router with no goodies. Internally uses a [Radix Tree](https://en.wikipedia.org/wiki/Radix_tree)
138
+
router that will bring better performance over iterative regular expressions matching.
139
+
```js
140
+
constcero=require('../index')
141
+
const { router, server } =cero({
142
+
router:require('find-my-way')()
143
+
})
144
+
145
+
router.on('GET', '/hi', (req, res) => {
146
+
res.end('Hello World!')
147
+
})
148
+
149
+
server.listen(3000)
150
+
```
151
+
152
+
# Servers
153
+
`0http` is just a wrapper for the servers and routers implementations you provide.
154
+
```js
155
+
constcero=require('0http')
156
+
157
+
const { router, server } =cero({
158
+
server: yourCustomServerInstance
159
+
})
160
+
```
161
+
162
+
## Node.js http.Server
163
+
If no server is provided by configuration, the standard Node.js [http.Server](https://nodejs.org/api/http.html#http_class_http_server) implementation is used.
164
+
Because this server offers the best balance between Node.js ecosystem compatibility and performance, we highly recommend it for most use cases.
0 commit comments