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:

  • routes table a list-like table of routes (optional)
  • opts table options table (optional)

Returns:

  1. a new router, or nil
  2. 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)
generated by LDoc 1.5.0 Last updated 2024-03-01 01:33:25