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

API without invoking handlers #28

Open
kirs opened this issue Aug 7, 2019 · 3 comments
Open

API without invoking handlers #28

kirs opened this issue Aug 7, 2019 · 3 comments

Comments

@kirs
Copy link
Contributor

kirs commented Aug 7, 2019

Hey there! Thank you for this awesome library.

I'm interested in using it in nginx as a router, but for what I'm looking to do, I don't want to invoke a route handler when a route is matched. All I want is to match a request to a route, and lookup that route's metadata.

An example in pseudocode:

local r3route = require "resty.r3"
local r3 = r3route.new({
  {
      path = [[/foo/{:\w+}/{:\w+}"]],
      method = {"GET"},
      metadata = { server: foo, datacenter: us-east }
  },
  {
      path = [[/bar/{:\w+}/{:\w+}]],
      host = "*.bar.com",
      metadata = { server: bar, datacenter: us-east }
  },
  {
      path = [[/alice/{:\w+}/{:\w+}]],
      metadata = { server: alice, datacenter: us-west }
  },
})

-- match_route is imaginary name, similar API to r3:dispatch
local metadata = r3:match_route("GET", "/alice/one/two")

metadata.server => alice
metadata.datacenter => us-west

I think this is very similar to existing API, with one difference in handler vs. metadata.
I'd be happy to contribute a patch once other contributors are onboard 👍

cc @membphis

@membphis
Copy link
Member

membphis commented Aug 8, 2019

I love this new style, it looks simpler. welcome new PR

@SenLinLeo
Copy link

SenLinLeo commented Aug 13, 2019

您好,感谢你提供的库!
我想请教一个问题,我要路由的URL是不定长的,比如: ip:7500/v1/foo/dir/test/......../test ; 可能有很多级。所以我用了正则匹配,但是。

  1. POST方法用不了正则,无法匹配。

  2. GET和POST方法 path一样的话两种方法都无法匹配,可能和前缀树的实现有关吧。
    代码如下:
    `local router_uri =
    {
    {
    path = "/v1/foo/{get_filename}",
    method = {"GET"},
    handler = main_controllers_get
    },
    {
    path = [[/v1/bar/{bucketname}/{get_filename:([\w-./])}]],
    method = {"GET"},
    handler = main_controllers_get
    },
    {
    path = "/v1/foo",
    method = {"POST"},
    handler = main_controllers_post
    },
    {
    path = [[/v1/bar/{bucketname}/{post_filename:([\w-./]
    )}]],
    method = {"POST"},
    handler = main_controllers_post
    }
    }

    local r3 = r3route.new(router_uri)

    r3:compile()

    local ok = r3:dispatch(ngx.var.uri , ngx.req.get_method())
    if not ok then
    ngx.exit(403)
    end`
    这种问题怎么解决了?

@membphis
Copy link
Member

@SenLinLeo I think that should be a bug of r3. It is not easy to resolve this bug i think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants