Module radix-router
Radix-Router is a lightweight high-performance and radix tree based router matching library.
Functions
Router.new ([routes[, opts]]) | create a new router. |
Router:match (path[, ctx[, params[, matched]]]) | find a handler of route that matches the path and ctx. |
Functions
- Router.new ([routes[, opts]])
-
create a new router.
Parameters:
Returns:
- a new router, or nil
- cannot create router error
Usage:
local router, err = router.new({ { paths = { "/hello-{word}" }, methods = { "GET" }, handler = "hello handler", }, })
- Router:match (path[, ctx[, params[, matched]]])
-
find a handler of route that matches the path and ctx.
Parameters:
- path string the request path
- ctx table the request context (optional)
- params table a table to store the parsed parameters (optional)
- matched table a table to store the matched conditions, such as path, method and host (optional)
Returns:
-
the handler of a route matches the path and ctx, or nil if not found
Usage:
local params = {} local matched = {} local handler = router:match("/hello-world", { method = "GET" }, params, matched)