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
Lua-Radix-Router is a lightweight high-performance router, written in pure Lua. The router is easy to use, with only two methods, `Router.new()` and `Router:match()`. It can be integrated into different runtimes such as Lua application, LuaJIT, or OpenResty.
8
6
7
+
Lua-Radix-Router is a lightweight high-performance router library written in pure Lua. It's easy to use with only two exported functions, `Router.new()` and `router:match()`.
9
8
9
+
The router is optimized for high performance. It combines HashTable(O(1)) and Compressed Trie(or Radix Tree, O(m) where m is the length of path being searched) for efficient matching. Some of the utility functions have the LuaJIT version for better performance, and will automatically switch when running in LuaJIT. It also scales well even with long paths and a large number of routes.
10
10
11
-
The router is designed for high performance. A compressing dynamic trie (radix tree) is used for efficient matching. Even with millions of routes containing complex paths, matching can still be done in 1 nanosecond.
11
+
The router can be run in different runtimes such as Lua, LuaJIT, or OpenResty.
12
12
13
13
## 🔨 Features
14
14
15
-
-**Variables in path**: Syntax `{varname}`.
16
-
-`/users/{id}/profile-{year}.{format}`: multiple variables in one path segment is allowed
17
-
-**Prefix matching**: Syntax `{*varname}`.
18
-
-`/api/authn/{*path}`
19
-
-**Variables binding**: The router automatically injects the binding result for you during matching.
20
-
-**Best performance**: The fastest router in Lua/LuaJIT. See [Benchmarks](#-Benchmarks).
-**Trailing slash match**: You can make the Router to ignore the trailing slash by setting `trailing_slash_match` to true. For example, /foo/ to match the existing /foo, /foo to match the existing /foo/.
23
-
-**Custom matcher**: The router has two efficient matchers built in, MethodMatcher(`method`) and HostMatcher(`host`). They can be disabled via `opts.matcher_names`. You can also add your custom matchers via `opts.matchers`. For example, an IpMatcher to evaluate whether the `ctx.ip` is matched with the `ips` of a route.
15
+
**Patterned path:** You can define named or unnamed patterns in path with pattern syntax "{}" and "{*}"
16
+
17
+
- named variables: `/users/{id}/profile-{year}.{format}`, matches with /users/1/profile-2024.html.
18
+
- named prefix: `/api/authn/{*path}`, matches with /api/authn/foo and /api/authn/foo/bar.
19
+
20
+
**Variable binding:** Stop manually parsing the URL, let the router injects the binding variables for you.
21
+
22
+
**Best performance:** The fastest router in Lua/LuaJIT. See [Benchmarks](#-Benchmarks).
23
+
24
+
**OpenAPI friendly:** OpenAPI(Swagger) is fully compatible.
25
+
26
+
**Trailing slash match:** You can make the Router to ignore the trailing slash by setting `trailing_slash_match` to true. For example, /foo/ to match the existing /foo, /foo to match the existing /foo/.
27
+
28
+
**Custom matcher:** The router has two efficient matchers built in, MethodMatcher(`method`) and HostMatcher(`host`). They can be disabled via `opts.matcher_names`. You can also add your custom matchers via `opts.matchers`. For example, an IpMatcher to evaluate whether the `ctx.ip` is matched with the `ips` of a route.
24
29
25
30
**Features in the roadmap**:
26
31
@@ -39,7 +44,7 @@ luarocks install radix-router
39
44
Or from source
40
45
41
46
```
42
-
make build
47
+
make install
43
48
```
44
49
45
50
Get started by an example:
@@ -81,7 +86,7 @@ assert(params.year == "2023")
81
86
assert(params.format=="pdf")
82
87
```
83
88
84
-
For more usage samples, please refer to the `/samples` directory.
89
+
For more usage samples, please refer to the [/samples](/samples) directory. For more use cases, please check out https://github.com/vm-001/lua-radix-router-use-cases.
85
90
86
91
## 📄 Methods
87
92
@@ -101,11 +106,11 @@ local router, err = Router.new(routes, opts)
|`paths`</br> *required\**| A list of paths that match the Route.</br> |
117
122
|`methods`</br> *optional*| A list of HTTP methods that match the Route. </br> |
118
-
|`hosts`</br> *optional*| A list of hostnames that match the Route. Note that the value is case-sensitive. Wildcard hostnames are supported. For example, `*.foo.com` can match with `a.foo.com` or `a.b.foo.com`. |
123
+
|`hosts`</br> *optional*| A list of hostnames that match the Route. Note that the value is case-sensitive. Wildcard hostnames are supported. For example, `*.foo.com` can match with `a.foo.com` or `a.b.foo.com`. |
119
124
|`handler`</br> *required\**| The value of handler will be returned by `router:match()` when the route is matched. |
120
125
|`priority`</br> *optional*| The priority of the route in case of radix tree node conflict. |
121
-
|`expression`</br> *optional* (TDB) | The `expression` defines a customized matching condition by using expression language. |
0 commit comments