@@ -15,9 +15,10 @@ Zero friction HTTP framework:
1515> Check it yourself: https://web-frameworks-benchmark.netlify.app/result?f=feathersjs,0http,koa,fastify,nestjs-express,express,sails,nestjs-fastify,restana
1616
1717# Usage
18+ JavaScript:
1819``` js
19- const cero = require (' 0http' )
20- const { router , server } = cero ()
20+ const zero = require (' 0http' )
21+ const { router , server } = zero ()
2122
2223router .get (' /hello' , (req , res ) => {
2324 res .end (' Hello World!' )
@@ -34,6 +35,24 @@ router.post('/do', (req, res) => {
3435server .listen (3000 )
3536```
3637
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+
3756# Routers
3857` 0http ` allows you to define the router implementation you prefer as soon as it support the following interface:
3958``` js
@@ -48,8 +67,8 @@ an internal(optional) LRU cache to store the matching results of the previous re
4867Supported HTTP verbs: ` GET, HEAD, PATCH, OPTIONS, CONNECT, DELETE, TRACE, POST, PUT `
4968
5069``` js
51- const cero = require (' 0http' )
52- const { router , server } = cero ({})
70+ const zero = require (' 0http' )
71+ const { router , server } = zero ({})
5372
5473// global middleware example
5574router .use (' /' , (req , res , next ) => {
@@ -94,7 +113,7 @@ Example passing configuration options:
94113
95114``` js
96115const sequential = require (' 0http/lib/router/sequential' )
97- const { router , server } = cero ({
116+ const { router , server } = zero ({
98117 router: sequential ({
99118 cacheSize: 2000
100119 })
@@ -121,8 +140,8 @@ router.get('/sayhi', (req, res) => {
121140### Nested Routers
122141You can simply use ` sequential ` router intances as nested routers:
123142``` js
124- const cero = require (' ../index' )
125- const { router , server } = cero ({})
143+ const zero = require (' ../index' )
144+ const { router , server } = zero ({})
126145
127146const nested = require (' 0http/lib/router/sequential' )()
128147nested .get (' /url' , (req , res , next ) => {
@@ -139,8 +158,8 @@ server.listen(3000)
139158Super-fast raw HTTP router with no goodies. Internally uses a [ Radix Tree] ( https://en.wikipedia.org/wiki/Radix_tree )
140159router that will bring better performance over iterative regular expressions matching.
141160``` js
142- const cero = require (' ../index' )
143- const { router , server } = cero ({
161+ const zero = require (' ../index' )
162+ const { router , server } = zero ({
144163 router: require (' find-my-way' )()
145164})
146165
@@ -154,9 +173,9 @@ server.listen(3000)
154173# Servers
155174` 0http ` is just a wrapper for the servers and routers implementations you provide.
156175``` js
157- const cero = require (' 0http' )
176+ const zero = require (' 0http' )
158177
159- const { router , server } = cero ({
178+ const { router , server } = zero ({
160179 server: yourCustomServerInstance
161180})
162181```
0 commit comments