@@ -11,45 +11,10 @@ npm create resty-app@latest -y
11
11
```
12
12
Then follow the instructions to complete the project.
13
13
14
- # Api
15
-
16
- ## new
17
-
18
- ``` lua
19
- (method ) Router :new ()
20
- -> Router
21
- ```
22
-
23
- create a router.
24
-
25
- ## insert
14
+ # Dependencies
26
15
27
- ``` lua
28
- (method ) Router :insert (path : string , handler : string |function , methods ?: string |string [])
29
- -> Router
30
- ```
31
-
32
- insert a route.
33
-
34
- ## extend
35
-
36
- ``` lua
37
- --- @alias Route { [1] : string , [2] : function | string , [3] ?: string | string[] }
38
- (method ) Router :extend (routes : Route [])
39
- -> Router
40
- ```
41
-
42
- insert routes to a router.
43
-
44
- ## match
45
-
46
- ``` lua
47
- (method ) Router :match (path : string , method : string )
48
- -> string |function
49
- 2. { [string ]: string |number }?
50
- ```
51
-
52
- match a http request
16
+ * [ OpenResty] ( https://openresty.org/ )
17
+ * (Optional) [ lfs] ( https://luarocks.org/modules/hisham/luafilesystem ) or [ syscall.lfs] ( https://github.com/justincormack/ljsyscall ) - if you want to use ` fs ` method to load routes from directory
53
18
54
19
# Synopsis
55
20
@@ -62,6 +27,7 @@ local cnt = 0
62
27
local error_cnt = 0
63
28
64
29
-- Test events
30
+ -- for test purpose, assume the nginx is single-threaded
65
31
router :on (' add' , function (ctx )
66
32
cnt = cnt + 1
67
33
end )
169
135
router :get (" /func" , function (ctx )
170
136
return function ()
171
137
ngx .header .content_type = ' text/plain; charset=utf-8'
172
- ngx .say (" function called2 " )
138
+ ngx .say (" function called " )
173
139
end
174
140
end )
175
141
@@ -186,6 +152,64 @@ end)
186
152
return router
187
153
188
154
```
189
- ## reference
190
155
191
- - [ nginx api for lua] ( https://github.com/openresty/lua-nginx-module?tab=readme-ov-file#nginx-api-for-lua )
156
+ # Api
157
+
158
+ ## new
159
+
160
+ ``` lua
161
+ (method ) Router :new ()
162
+ -> Router
163
+ ```
164
+
165
+ create a router.
166
+
167
+ ## insert
168
+
169
+ ``` lua
170
+ (method ) Router :insert (path : string , handler : string |function , methods ?: string |string [])
171
+ -> Router
172
+ ```
173
+
174
+ insert a route.
175
+
176
+ ## extend
177
+
178
+ ``` lua
179
+ --- @alias Route { [1] : string , [2] : function | string , [3] ?: string | string[] }
180
+ (method ) Router :extend (routes : Route [])
181
+ -> Router
182
+ ```
183
+
184
+ insert routes to a router.
185
+
186
+ ## match
187
+
188
+ ``` lua
189
+ (method ) Router :match (path : string , method : string )
190
+ ->
191
+ 1. string |function
192
+ 2. { [string ]: string |number }?
193
+ ```
194
+
195
+ match a http request
196
+
197
+ ## run
198
+ ``` lua
199
+ (method ) Router :run ()
200
+ -> nil
201
+ ```
202
+ dispatch http request
203
+
204
+ ## fs
205
+
206
+ ``` lua
207
+ (method ) Router :fs (dir : string )
208
+ -> nil
209
+ ```
210
+
211
+ load routes from directory (requires ` lfs ` or ` syscall.lfs ` module).
212
+
213
+ # reference
214
+
215
+ - [ nginx api for lua] ( https://github.com/openresty/lua-nginx-module?tab=readme-ov-file#nginx-api-for-lua )
0 commit comments