Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: improvement #3

Merged
merged 2 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI pipeline
name: test

on:
pull_request: {}
Expand Down
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
# Lua-radix-router
# 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)

Lua-radix-router is a lightweight high performance router for Lua/LuaJIT.
Lua-radix-router is a lightweight high-performance router written in Lua.

It supports OpenAPI style variables path and prefix matching by using the ` { }` symbol.

## Installation
- `/users/{id}/profile-{year}.{format}`
- `/api/authn/{*path}`

Parameter binding is also supported.

The router is designed for high performance. A compressing dynamic trie (radix tree) is used for efficient matching. Even with millions of routes and complex paths, matching can still be done in 1 nanosecond.

## 🔨 Installation

Install via LuaRocks:

```
luarocks install radix-router
```

## Usage
## 📖 Usage

```lua
local Router = require "radix-router"
Expand Down Expand Up @@ -53,7 +61,7 @@ assert(params.year == "2023")
assert(params.format == "pdf")
```

## Methods
## 📄 Methods

### new
Creates a radix router instance.
Expand All @@ -64,7 +72,7 @@ local router, err = Router.new(routes)

**Parameters**

- **routes **(`table|nil`): the array-like Route table.
- **routes**(`table|nil`): the array-like Route table.



Expand All @@ -74,7 +82,8 @@ Route defines the matching conditions for its handler.
| ----------------------------- | ------------------------------------------------------------ |
| `paths` *required\** | The path list of matching condition. |
| `methods` *optional* | The method list of matching condition. |
| `handler` *required\** | The `handler` will be returned by `router:match()` when the route is matched. |
| `handler` *required\** | The value of handler will be returned by `router:match()` when the route is matched. |
| `priority` *optional* | The priority of the route in case of radix tree node conflict. |
| `expression` *optional* (TDB) | The `expression` defines a customized matching condition by using expression language. |


Expand All @@ -93,4 +102,7 @@ local handler = router:match(path, ctx, params)
- **ctx**(`table|nil`): the optional condition ctx to use for matching.
- **params**(`table|nil`): the optional table to use for storing the parameters binding result.

# Benchmarks
## 🚀 Benchmarks


## License
2 changes: 1 addition & 1 deletion src/parser/style/default.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--- Todo style path parser.
--- Default style path parser.
--
-- Parses the path into multiple tokens with patterns.
--
Expand Down
Loading