Skip to content

Commit 3eafae4

Browse files
authored
doc: improve README.md (#34)
1 parent d57a243 commit 3eafae4

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
3939
- name: build
4040
run: |
41-
make build
41+
make install
4242
4343
- name: run tests
4444
run: |

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
build:
1+
.PHONY: install test test-coverage bench lint
2+
3+
install:
24
luarocks make
35

46
test:
@@ -7,6 +9,9 @@ test:
79
test-coverage:
810
busted --coverage spec/
911

12+
lint:
13+
luacheck .
14+
1015
CMD=luajit
1116
bench:
1217
RADIX_ROUTER_ROUTES=100000 RADIX_ROUTER_TIMES=10000000 $(CMD) benchmark/static-paths.lua

README.md

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1-
# Lua-Radix-Router [![Build Status](https://github.com/vm-001/lua-radix-router/actions/workflows/test.yml/badge.svg)](https://github.com/vm-001/lua-radix-router/actions/workflows/test.yml) [![Coverage Status](https://coveralls.io/repos/github/vm-001/lua-radix-router/badge.svg)](https://coveralls.io/github/vm-001/lua-radix-router)
1+
# Lua-Radix-Router [![Build Status](https://github.com/vm-001/lua-radix-router/actions/workflows/test.yml/badge.svg)](https://github.com/vm-001/lua-radix-router/actions/workflows/test.yml) [![Build Status](https://github.com/vm-001/lua-radix-router/actions/workflows/sample.yml/badge.svg)](https://github.com/vm-001/lua-radix-router/actions/workflows/sample.yml) [![Coverage Status](https://coveralls.io/repos/github/vm-001/lua-radix-router/badge.svg)](https://coveralls.io/github/vm-001/lua-radix-router) ![Lua Versions](https://img.shields.io/badge/Lua-%205.2%20|%205.3%20|%205.4-blue.svg)
22

33
English | [中文](README.zh.md)
44

5-
---
65

7-
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.
86

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()`.
98

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.
1010

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.
1212

1313
## 🔨 Features
1414

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).
21-
- **OpenAPI friendly**: OpenAPI(Swagger) fully compatible.
22-
- **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.
2429

2530
**Features in the roadmap**:
2631

@@ -39,7 +44,7 @@ luarocks install radix-router
3944
Or from source
4045

4146
```
42-
make build
47+
make install
4348
```
4449

4550
Get started by an example:
@@ -81,7 +86,7 @@ assert(params.year == "2023")
8186
assert(params.format == "pdf")
8287
```
8388

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.
8590

8691
## 📄 Methods
8792

@@ -101,11 +106,11 @@ local router, err = Router.new(routes, opts)
101106

102107
The available options are as follow
103108

104-
| NAME | TYPE | DEFAULT | DESCRIPTION |
105-
| -------------------- | ------- | -------------------- | --------------------------------------------------- |
106-
| trailing_slash_match | boolean | false | whether to enable the trailing slash match behavior |
107-
| matcher_names | table | { "method", "host" } | enabled built-in macher list |
108-
| matchers | table | { } | custom matcher list |
109+
| NAME | TYPE | DEFAULT | DESCRIPTION |
110+
| -------------------- | ------- | ------------------ | --------------------------------------------------- |
111+
| trailing_slash_match | boolean | false | whether to enable the trailing slash match behavior |
112+
| matcher_names | table | {"method", "host"} | enabled built-in macher list |
113+
| matchers | table | { } | custom matcher list |
109114

110115

111116

@@ -115,10 +120,9 @@ Route defines the matching conditions for its handler.
115120
|-------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
116121
| `paths`</br> *required\** | A list of paths that match the Route.</br> |
117122
| `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`. |
119124
| `handler`</br> *required\** | The value of handler will be returned by `router:match()` when the route is matched. |
120125
| `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. |
122126

123127

124128

@@ -219,7 +223,7 @@ router.trie = / nil
219223
To run the benchmark
220224

221225
```$ make bench
222-
$ make build
226+
$ make install
223227
$ make bench
224228
```
225229

@@ -327,3 +331,7 @@ Memory : 2.72 MB
327331

328332

329333
## License
334+
335+
BSD 2-Clause License
336+
337+
Copyright (c) 2024, Yusheng Li

README.zh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ luarocks install radix-router
4444
或者从源码安装
4545

4646
```
47-
make build
47+
make install
4848
```
4949

5050
通过示例开始:
@@ -136,7 +136,7 @@ local handler = router:match(path, ctx, params)
136136
#### 用法
137137

138138
```
139-
$ make build
139+
$ make install
140140
$ make bench
141141
```
142142

0 commit comments

Comments
 (0)