@@ -15,9 +15,10 @@ Zero friction HTTP framework:
15
15
> Check it yourself: https://web-frameworks-benchmark.netlify.app/result?f=feathersjs,0http,koa,fastify,nestjs-express,express,sails,nestjs-fastify,restana
16
16
17
17
# Usage
18
+ JavaScript:
18
19
``` js
19
- const cero = require (' 0http' )
20
- const { router , server } = cero ()
20
+ const zero = require (' 0http' )
21
+ const { router , server } = zero ()
21
22
22
23
router .get (' /hello' , (req , res ) => {
23
24
res .end (' Hello World!' )
@@ -34,6 +35,24 @@ router.post('/do', (req, res) => {
34
35
server .listen (3000 )
35
36
```
36
37
38
+ TypeScript:
39
+ ``` ts
40
+ import zero from ' 0http'
41
+ import { Protocol } from ' 0http/common'
42
+
43
+ const { router, server } = zero <Protocol .HTTP >()
44
+
45
+ router .use ((req , res , next ) => {
46
+ return next ()
47
+ })
48
+
49
+ router .get (' /hi' , (req , res ) => {
50
+ res .end (` Hello World from TS! ` )
51
+ })
52
+
53
+ server .listen (3000 )
54
+ ```
55
+
37
56
# Routers
38
57
` 0http ` allows you to define the router implementation you prefer as soon as it support the following interface:
39
58
``` js
@@ -48,8 +67,8 @@ an internal(optional) LRU cache to store the matching results of the previous re
48
67
Supported HTTP verbs: ` GET, HEAD, PATCH, OPTIONS, CONNECT, DELETE, TRACE, POST, PUT `
49
68
50
69
``` js
51
- const cero = require (' 0http' )
52
- const { router , server } = cero ({})
70
+ const zero = require (' 0http' )
71
+ const { router , server } = zero ({})
53
72
54
73
// global middleware example
55
74
router .use (' /' , (req , res , next ) => {
@@ -94,7 +113,7 @@ Example passing configuration options:
94
113
95
114
``` js
96
115
const sequential = require (' 0http/lib/router/sequential' )
97
- const { router , server } = cero ({
116
+ const { router , server } = zero ({
98
117
router: sequential ({
99
118
cacheSize: 2000
100
119
})
@@ -121,8 +140,8 @@ router.get('/sayhi', (req, res) => {
121
140
### Nested Routers
122
141
You can simply use ` sequential ` router intances as nested routers:
123
142
``` js
124
- const cero = require (' ../index' )
125
- const { router , server } = cero ({})
143
+ const zero = require (' ../index' )
144
+ const { router , server } = zero ({})
126
145
127
146
const nested = require (' 0http/lib/router/sequential' )()
128
147
nested .get (' /url' , (req , res , next ) => {
@@ -139,8 +158,8 @@ server.listen(3000)
139
158
Super-fast raw HTTP router with no goodies. Internally uses a [ Radix Tree] ( https://en.wikipedia.org/wiki/Radix_tree )
140
159
router that will bring better performance over iterative regular expressions matching.
141
160
``` js
142
- const cero = require (' ../index' )
143
- const { router , server } = cero ({
161
+ const zero = require (' ../index' )
162
+ const { router , server } = zero ({
144
163
router: require (' find-my-way' )()
145
164
})
146
165
@@ -154,9 +173,9 @@ server.listen(3000)
154
173
# Servers
155
174
` 0http ` is just a wrapper for the servers and routers implementations you provide.
156
175
``` js
157
- const cero = require (' 0http' )
176
+ const zero = require (' 0http' )
158
177
159
- const { router , server } = cero ({
178
+ const { router , server } = zero ({
160
179
server: yourCustomServerInstance
161
180
})
162
181
```
0 commit comments